Skip to content

Instantly share code, notes, and snippets.

@kaizer1v
Last active May 22, 2019 03:01
Show Gist options
  • Save kaizer1v/9dd36d4733c50e11d5bb to your computer and use it in GitHub Desktop.
Save kaizer1v/9dd36d4733c50e11d5bb to your computer and use it in GitHub Desktop.
Produces all the factors of a given integer.
/* 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