-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lesson 2: mostCommon - Takes in an array of numbers & find the most common number (using objects might help) #47
Comments
const val = arr[i]; Object.keys(map) // returns [1,0,2,4] |
First, build an object (key is number, value is how many times that number shows up in the array) |
…bers & find the most common number
…mbers & find the most common number
…nd the most common number
*Going off what Song explained; once you find the maximum value it is only clear what the most common number is. Input: [1,0,2,2,4] When you create an object for this array it will look like: { 1: 1, 0: 1, 2: 2, 4: 1 }. 2 has the maximum value because it is in the array twice. Therefore, you return 2. |
Solve garageScript#47: Lesson 2: mostCommon -takes in an array of numbers & find …
Input: [1,0,2,2,4]
Output: 2
Input: [0,0,0,1,1,1,1]
Output: 1
The text was updated successfully, but these errors were encountered: