Consider the following array of arrays
const data = [[150, 1], [300, 2], [430, 1]]
If I were to use Lodash's countBy
, I could achieve the same result with ES6 syntax by writing
{ ...data.reduce((acc, row) => ({ ...acc, [row[1]]: (acc[row[1]] || 0) + 1 }), {}) }
. This will count the occurrences and store them in an object. How would you accomplish this using vanilla ES6 javascript?