In Javascript, I\'m trying to take an initial array of number values and count the elements inside it. Ideally, the result would be two new arrays, the first specifying each
ES6 solution with reduce (fixed):
const arr = [2, 2, 2, 3, 2] const count = arr.reduce((pre, cur) => (cur === 2) ? ++pre : pre, 0) console.log(count) // 4