Navigation Menu

Skip to content

Commit

Permalink
New way of checking if value is integer
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelk committed Mar 23, 2011
1 parent d708843 commit 0704664
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions functions/var/is_int.js
Expand Up @@ -5,6 +5,7 @@ function is_int (mixed_var) {
// + revised by: Matt Bradley
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: WebDevHobo (http://webdevhobo.blogspot.com/)
// + improved by: Rafał Kukawski (http://blog.kukawski.pl)
// % note 1: 1.0 is simplified to 1 before it can be accessed by the function, this makes
// % note 1: it different from the PHP implementation. We can't fix this unfortunately.
// * example 1: is_int(23)
Expand All @@ -15,9 +16,5 @@ function is_int (mixed_var) {
// * returns 3: false
// * example 4: is_int(true)
// * returns 4: false
if (typeof mixed_var !== 'number') {
return false;
}

return !(mixed_var % 1);
return mixed_var === ~~mixed_var;
}

0 comments on commit 0704664

Please sign in to comment.