Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const array = [3, 'a', 'a', 'a', 2, 3, 'a', 3, 'a', 2, 4, 9, 3];
- const getMostFrequentValue = array => {
- const countAllValues = array.reduce((acc, curr) => {
- if (curr in acc) {
- return { ...acc, [curr]: acc[curr] + 1 }
- }
- return { ...acc, [curr]: 1 }
- }, {})
- const countedValues = Object.values(countAllValues);
- return Math.max(...countedValues);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement