Discuss / JavaScript / 素数

素数

Topic source

NotFatCat

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

  • 1

Reply