js-mentorship-razvan / javascript

Javascript study notes
GNU General Public License v3.0
22 stars 2 forks source link

Find Count of Most Frequent Item in an Array #506

Closed RazvanBugoi closed 4 years ago

RazvanBugoi commented 4 years ago

https://www.codewars.com/kata/56582133c932d8239900002e/train/javascript

RazvanBugoi commented 4 years ago
function mostFrequentItemCount(collection) {
  let obj = {};
  if (collection.length > 0 ) {
  collection.map((el) => el in obj ? obj[el] += 1 : obj[el] = 1);
  } else return 0;
    return Math.max(...Object.values(obj));
}