Last active
February 6, 2017 20:06
-
-
Save andrescabana86/f31d661e693b0c5c6759d8361b7dafac to your computer and use it in GitHub Desktop.
All factors of a number O( log(n/2) ) Raw
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 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