A collection of codes containing the solution you are looking for.
A collection of codes containing the solution you are looking for.
function getDivisors(n) { //Logic var res = []; for(var i = 1; i <= Math.sqrt(n); i++) { if(n % i === 0) { if(n / i === i) { res.push(i); } } else { res.push(i); res.push(parseInt(n / i)); } } return res; }