Skip to content

Instantly share code, notes, and snippets.

@syzer
Created April 8, 2015 18:49
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 syzer/343604fa29a1b223dfde to your computer and use it in GitHub Desktop.
Save syzer/343604fa29a1b223dfde to your computer and use it in GitHub Desktop.
predict
// simples would be return dataBase[word];
// string => array
function predict(word) {
var needle = dataBase[word];
if (!needle) {
return [];
}
var total = _.reduce(needle, function (acc, el) {
return acc + el;
});
needle = _.objToSortedArr(needle);
return _(needle)
.map(function (el) {
el[1] = (el[1] / total).toFixed(3);
return el;
})
.map(function (el) {
return el.join(',');
})
.value();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment