function factors( n ){ var u = Math.floor( Math.sqrt( n ) ), i, f = [], e = [];
for( i = 1 ; i <= u; i++ ) { if( n % i == 0 ) { f.push( i ); e.unshift( n / i ); } } if( e[ 0 ] == u ) e.shift(); return f.concat( e ); }
Here the minimized version (147 bytes)...
function factors(n,u,i,f,e){for(u=Math.sqrt(n)|0,i=1,e=[],f=[];i<=u;i++)if(n%i<1){f.push(i);e.unshift(n/i)}if(e[0]==u)e.shift();return f.concat(e)}
No comments:
Post a Comment