const getPrimes = length => { return Array.from({ length }, (_, i) => ++i).reduce((a, b) => { let max = Math.floor(Math.sqrt(b)); if (a.slice(1, max).every(e => b % e)) a.push(b); return a }, []) } console.log(getPrimes(120))