Last active
December 19, 2015 16:29
-
-
Save tomgullo/5984461 to your computer and use it in GitHub Desktop.
get three words that appear most often in a string, using underscore
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
//get the three words that appear most often in a single string | |
var s = "two one two three four one one eight one two four eight three one" | |
var p = _.pairs(_.countBy( s.split(" "))) | |
var f = _.sortBy(p, function (p) { return p[1]; }).reverse().slice(0,3); | |
console.log( | |
f | |
) | |
//output [["one", 5], ["two", 3], ["eight", 2]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment