Discuss / JavaScript / 素数

素数

Topic source

腾腾2318

#1 Created at ... [Delete] [Delete and Lock User]
return arr.filter(function(s) {
    var max = s;
    if (s <= 1) return false;
    for (var i = 2; i <= Math.abs(Math.sqrt(max)); i++) {
        if (s % i == 0 ) return false;

    }
    return true;

});

  • 1

Reply