Write a function that returns a map of the totaled occurrences of elements within an array.
Anonymous
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; }, {}); }
Check out your Company Bowl for anonymous work chats.