Created
February 11, 2017 06:35
-
-
Save jpdevries/240012bcbf74593ea2d3b8e3b76c801c to your computer and use it in GitHub Desktop.
Check if a Number is Even with less division
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* function isEven(num) { if num is a really large number this will require A LOT of recursive division | |
return num % 2 === 0; // infinite module divisions | |
}*/ | |
function isEven(num) { | |
num = parseInt(num.toString().slice(-1)); // the rightmost digit of any even number is also even so just check that | |
return num % 2 === 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment