Last active
February 22, 2020 20:06
-
-
Save florianmaxim/9f0078dad768e86ae4a32135d980c9e9 to your computer and use it in GitHub Desktop.
Factorize a number
This file contains hidden or 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 factorize(n) { | |
| const x = n; | |
| const factors = []; | |
| for (let i = 2; i <= n; i++) { | |
| let mod = n % i; | |
| console.log(`${n}%${i}=${mod}`); | |
| if (mod === 0) { | |
| factors.push(i); | |
| n = n / i; | |
| } | |
| } | |
| return factors; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment