Problem statement
Check if a number is even.
input: 8
output: true
var isEven = function(n) {
// start here
};
Solution:
var isEven = function (n) {
if (n === 0) return true;
else if (n === 1) return false;
else {
return isEven(n - 2);
}
};
Top comments (1)
Interesting. If there was a contest for the worst way to check for evenness, then using recursion would definitely win the award.