Skip to content

Instantly share code, notes, and snippets.

@jpdevries
Created February 11, 2017 06:35
Show Gist options
  • Save jpdevries/240012bcbf74593ea2d3b8e3b76c801c to your computer and use it in GitHub Desktop.
Save jpdevries/240012bcbf74593ea2d3b8e3b76c801c to your computer and use it in GitHub Desktop.
Check if a Number is Even with less division
/* 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