//5以上 8以下を取り出す
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
let result = arr.filter((val) => val >= 5 && val <=8)

console.log(result) // [5,6,7,8]


//素数を取り出す
const arr2 = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
let result2 = arr2.filter((val) => {
  for (let i = 2; i < val; i++) {
    if (val % i == 0) {
      return false;
    }
  }
  return val > 1;
})

console.log(result2) // [2,3,5,7]

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.