Created
September 21, 2017 21:47
-
-
Save matinkaboli/057d63f46a41954bd4fe56d5f4b07ee8 to your computer and use it in GitHub Desktop.
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
// This is slow | |
for (let i = 1;; i++) { | |
let count = 0; | |
for (let j = 1; j < 20; j++) { | |
if (i % j === 0) { | |
count += 1; | |
} | |
} | |
if (count === 19) { | |
console.log(i); | |
break; | |
} | |
} | |
// This is fast | |
for (let i = 1;; i++) { | |
if (i % 1 === 0) { | |
if (i % 2 === 0) { | |
if (i % 3 === 0) { | |
if (i % 4 === 0) { | |
if (i % 5 === 0) { | |
if (i % 6 === 0) { | |
if (i % 7 === 0) { | |
if (i % 8 === 0) { | |
if (i % 9 === 0) { | |
if (i % 10 === 0) { | |
if (i % 11 === 0) { | |
if (i % 12 === 0) { | |
if (i % 13 === 0) { | |
if (i % 14 === 0) { | |
if (i % 15 === 0) { | |
if (i % 16 === 0) { | |
if (i % 17 === 0) { | |
if (i % 18 === 0) { | |
if (i % 19 === 0) { | |
console.log(i); | |
break; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment