UNPKG

hexo-related-posts

Version:

Hexo plugin that generates related posts list with TF/IDF algorithm

13 lines (9 loc) 298 B
const calculateTf = (vector) => { const result = {}; const total = Object.keys(vector).reduce((result, word) => result + vector[word], 0); for (const word of Object.keys(vector)) { result[word] = vector[word] / total; } return result; } module.exports = calculateTf;