Last active
May 22, 2019 03:01
-
-
Save kaizer1v/9dd36d4733c50e11d5bb to your computer and use it in GitHub Desktop.
Produces all the factors of a given integer.
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
/* produces the factors of a given number */ | |
function _factors(n) { | |
var factors = [1, n]; | |
for(var i = 2; i <= Math.floor(n/i); i++) { | |
if(n % i === 0) | |
if(i === n/i) { | |
factors.push(i); | |
} | |
else | |
factors.push(i, n/i); | |
} | |
return factors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment