Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #remove #prime #numbers #js
ADD COMMENT
Topic
Name
4+1 =