Skip to content

Instantly share code, notes, and snippets.

@fakenickels
Last active December 25, 2015 01:09
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 fakenickels/6892460 to your computer and use it in GitHub Desktop.
Save fakenickels/6892460 to your computer and use it in GitHub Desktop.
The same algorithm of frequently_words.sh in JavaScript
function analyse( text ){
var words = {},
text = text.toLowerCase()
.replace(/[.,]+/g, '')
.replace(/[^\w\s\t\n]+/, '')
.split(' ');
for( var i in text ){
if( words[ text[i] ] == undefined )
words[ text[i] ] = 1;
else
words[ text[i] ] += 1;
}
return words;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment