Advertisement
Guest User

Untitled

a guest
Sep 26th, 2019
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const array = [3, 'a', 'a', 'a', 2, 3, 'a', 3, 'a', 2, 4, 9, 3];
  2.  
  3. const getMostFrequentValue = array => {
  4.   const countAllValues = array.reduce((acc, curr) => {
  5.     if (curr in acc) {
  6.       return { ...acc, [curr]: acc[curr] + 1 }
  7.     }
  8.  
  9.     return { ...acc, [curr]: 1 }
  10.   }, {})
  11.  
  12.   const countedValues = Object.values(countAllValues);
  13.   return Math.max(...countedValues);
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement