mirror of
https://github.com/scratchfoundation/scratch-analysis.git
synced 2025-08-28 22:09:00 -04:00
Initial working version
This commit is contained in:
parent
4f28eeef52
commit
590b71a0aa
22 changed files with 1414 additions and 0 deletions
23
lib/utility.js
Normal file
23
lib/utility.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
* Utility methods for costructing Scratch project summaries.
|
||||
*/
|
||||
class Utility {
|
||||
/**
|
||||
* Tallys term frequency from an array of strings.
|
||||
* @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;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = Utility;
|
Loading…
Add table
Add a link
Reference in a new issue