Discuss / JavaScript / 有点麻烦

有点麻烦

Topic source

低位

#1 Created at ... [Delete] [Delete and Lock User]
function get_primes(arr) {
    return arr.filter(function(item){
        if(item === 1){
            return false;;
        }
        if(item === 2){
            return true;
        }
        for(let i=2;i<=Math.ceil(Math.sqrt(item));i++){
            if(item % i === 0){
                return false;
            }
        }
        return true;
    });
}

  • 1

Reply