Node.js examples for Number:Algorithm
Get all divisors for a number
Number.prototype.hasDiv = function( n ) { return Number.isInteger( this / n ) } function sum( ary ) { var out = 0//from w w w. j a v a 2 s.c om for (var n in ary) { out += ary[n] } return out } function divisors( n ) { out = [] for ( var i = 1; i < n; i++ ) { if ( n.hasDiv( i ) ) { out.push( i ) } } return out }