Skip to content

Instantly share code, notes, and snippets.

@andrescabana86
Last active February 6, 2017 20:06
Show Gist options
  • Save andrescabana86/f31d661e693b0c5c6759d8361b7dafac to your computer and use it in GitHub Desktop.
Save andrescabana86/f31d661e693b0c5c6759d8361b7dafac to your computer and use it in GitHub Desktop.
All factors of a number O( log(n/2) ) Raw
function getFactorsOf(number) {
var factors = [];
var factor = 1;
var stopped = false;
while (stopped != true) {
if (number % factor === 0) {
let a = number / factor;
let b = factor;
if (b >= a) {
stopped = true;
if (b == a) {
factors = factors.concat([b]);
}
} else {
factors = factors.concat([b,a]);
}
}
factor++;
}
return factors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment