Last active
January 19, 2016 16:23
-
-
Save cosmopeon/85b7f6d6556820bb5186 to your computer and use it in GitHub Desktop.
This file contains 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 mostCommon (array) { | |
return array | |
.filter(function (value, index, array) { | |
return array.indexOf(value) === index; | |
}) | |
.map(function(uniqueItem) { | |
var count = 0; | |
array.forEach(function(item) { | |
if (uniqueItem === item) { | |
count++; | |
} | |
}); | |
return {name: uniqueItem, count: count}; | |
}) | |
.sort(function(a, b) { | |
return b.count - a.count; | |
})[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment