1

I need some help separating my app into the top 3 most common values that show up in the array.

I can't wrap my head around how to do this. I've tried several array methods or pushing into empty arrays but I don't know how to approach this problem.

var businessNames = ['walmart', '7-eleven', 'mcdonalds', 'walmart', 'mcdonalds', 'mcdonalds', 'DQ', 'bestbuy', 'sonic', 'DQ', 'DQ', 'DQ', 'sonic', ]
//my function didnt work so i won't show my sad attempt
Banzay
  • 9,310
  • 2
  • 27
  • 46
jawad727
  • 11
  • 1
  • 2
    Please show your sad attempt so that we can help you make it a happy attempt. – Zim84 May 22 '19 at 08:03
  • While the duplicate answer has some very good hints on how to do this, I feel it's a little steep for a beginner. I would suggest iterating the array, putting "new" values into a dictionary with a count of 1 and updating count of known values. Having the dictionary it would be trivial to find the three with max occurrences (except for what to do in the case of a tie). – Palle Due May 22 '19 at 08:14

0 Answers0