📜  删除非素数 js - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:44.048000             🧑  作者: Mango

代码示例1
var numArray = [2, 3, 4, 5, 6, 7, 8, 9, 10]

numArray = numArray.filter((number) => {
  for (var i = 2; i <= Math.sqrt(number); i++) {
    if (number % i === 0) return false;
  }
  return true;
});

console.log(numArray);