Skip to content

Instantly share code, notes, and snippets.

@ipassynk
Created August 21, 2016 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipassynk/b81e4c5106344a5f86d2eff99a6755ab to your computer and use it in GitHub Desktop.
Save ipassynk/b81e4c5106344a5f86d2eff99a6755ab to your computer and use it in GitHub Desktop.
let words = "aaa ggg aaa ggg aaa ffff aaa ggg aaa ggg aaa fff rrrr aaa";
let y = _.compose(
_.get('word'),
_.head,
_.orderBy('count', 'desc'),
_.map(p=>({word:p[0], count:p[1]})),
_.toPairs,
_.reduce((acc, next) => {
acc[next] = (acc[next] && acc[next]+1) || 1;
return acc;
}, {}),
_.split(' ')
)(words);
console.log(y);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment