Created
April 8, 2015 18:49
-
-
Save syzer/343604fa29a1b223dfde to your computer and use it in GitHub Desktop.
predict
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
// 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