scratch-analysis/lib/utility.js

24 lines
563 B
JavaScript
Raw Normal View History

2018-12-17 18:11:08 -05:00
/**
* Utility methods for costructing Scratch project summaries.
*/
class Utility {
/**
2018-12-17 20:12:21 -05:00
* Tallies term frequency from an array of strings.
2018-12-17 18:11:08 -05:00
* @param {array} input Array of strings
* @return {object} Frequency information
*/
static frequency (input) {
const result = Object.create(null);
for (let i in input) {
var term = input[i];
if (typeof result[term] === 'undefined') result[term] = 0;
result[term]++;
}
return result;
2018-12-17 20:05:13 -05:00
}
2018-12-17 18:11:08 -05:00
}
module.exports = Utility;