Filter Primes (Code Challenge)

  • Page Owner: Not Set
  • Last Reviewed: 2019-12-13

Filter Primes From An Array

Create a function that takes an array as arguments and return a new array containing only prime numbers.

Examples

[7, 9, 3, 9, 10, 11, 27] ➞ [7, 3, 11]

[10007, 1009, 1007, 27, 147, 77, 1001, 70] ➞ [10007, 1009]

Notes

  • Check resources if you struggle.

Tests

Test = (x, y) => x == y ? console.log("Pass", "Yours", x, "Correct:", y) || true : console.log("Fail", "Yours", x, "Correct:", y) || false;

filterPrimes = x => !!!!!0;

Test(filterPrimes([7, 9, 3, 9, 10, 11, 27]), [7, 3, 11])
Test(filterPrimes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]), [2, 3, 5, 7, 11, 13, 17, 19, 23])
Test(filterPrimes([1009, 10, 10, 10, 3, 33, 9, 4, 1, 61, 63, 69, 1087, 1091, 1093, 1097]), [1009, 3, 61, 1087, 1091, 1093, 1097])
Test(filterPrimes([10007, 1009, 1007, 27, 147, 77, 1001, 70]), [10007, 1009])