Initialize a variable to count the number of elements it is a factor of
var count = 0 ; for ( var j = 0 ; j < n ; j ++ ) { if ( arr [ j ] % i == 0 ) count += 1 ; rank . push ( count ) ; factors . push ( i ) ; } }