Advertisement
Guest User

Untitled

a guest
Sep 26th, 2019
127
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.   let matushkuEbalReduca = 0;
  13.   let forRulitSuka = null;
  14.  
  15.   for (const value in countAllValues) {
  16.     console.log(countAllValues[value], value);
  17.     if (countAllValues[value] > x) {
  18.       x = countAllValues[value];
  19.       res = `key ${value} times ${countAllValues[value]}`
  20.     }
  21.   }
  22.   return forRulitSuka;
  23. }
  24.  
  25. console.log(getMostFrequentValue([0, 0, 1]));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement