Created
March 29, 2016 14:36
-
-
Save mindplace/b30f04954bd02bbd9ee6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function findMode(array) { | |
| var hashOfValues = {}; | |
| for (var i=0; i < array.length; i++) { | |
| var count = 0; | |
| var current = array[i]; | |
| for (var j=0; j < array.length; j++) { | |
| var secondCurrent = array[j]; | |
| if (secondCurrent === current) { | |
| count += 1; | |
| } | |
| } | |
| hashOfValues[current] = count; | |
| } | |
| var highestCount = 0; | |
| for (var elem in hashOfValues) { | |
| if (hashOfValues[elem] > highestCount) { | |
| highestCount = hashOfValues[elem]; | |
| } | |
| } | |
| var items = new Array; | |
| for (var thing in hashOfValues) { | |
| if (hashOfValues[thing] === highestCount) { | |
| items.push(Number(thing)); | |
| } | |
| } | |
| console.log(items); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment