Skip to content

Instantly share code, notes, and snippets.

View offero's full-sized avatar

Chris offero

View GitHub Profile
@offero
offero / countWordsInText.js
Last active January 14, 2017 20:58 — forked from oscarmorrison/countWordsInText.js
count the words in a string, and order by popularity
function countWordsInText(text) {
let count = {};
let popularity = []; // maybe this should be an object due to JS array expansion logic
function updateWord(word, ct) {
if (popularity[ct-1]) {
popularity[ct-1].delete(word);
}
if (!popularity[ct]) {
popularity[ct] = new Set();