Answers for "remove non prime numbers js"

0

remove non prime numbers js

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);
Posted by: Guest on January-18-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language