Skip to content

Instantly share code, notes, and snippets.

@jpdevries jpdevries/iseven.js
Created Feb 11, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.