Netflix Interview Question

Write a function that returns a map of the totaled occurrences of elements within an array.

Interview Answer

Anonymous

Jul 15, 2017

function totalOccurences(arr) { if (!Array.isArray(arr)) throw new Error('Param as {array} is required'); return arr.reduce((acc, curr) => { if (acc.hasOwnProperty(curr)) acc[curr] += 1; else acc[curr] = 1; return acc; }, {}); }

3