Created
July 30, 2020 10:19
-
-
Save thejsa/f217d9e97b1a26575f23b36080417bdd to your computer and use it in GitHub Desktop.
is_even but really terrible (JS)
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 is_even(n) { | |
if(n == 0) return true; | |
var even_numbers = []; | |
for (var i = 0; i < n; i++) { | |
if(is_even(i)) { | |
even_numbers.push(i); | |
} | |
} | |
return (even_numbers.indexOf(n - 1) === -1); | |
} | |
// test | |
const TEST_MAX = 2048; | |
for(var i = 0; i <= TEST_MAX; i++) { | |
console.log(`Testing if ${i} is even...`); | |
console.time(`test${i}`); | |
let result = is_even(i); | |
console.timeEnd(`test${i}`); | |
console.log(`Result: ${result}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment