-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.js
53 lines (42 loc) · 2.1 KB
/
tools.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
module.exports = {
//removes common words from array
stripWords: function (array) {
var newArray = [];
for (idx in array) {
var word = array[idx];
if (!this.isStripped(word)) {
newArray.push(word.toLowerCase());
}
}
return newArray;
},
//checks if word is in the strippedwords array
isStripped: function (word) {
var strippedWords = ['the', 'a', 'of', 'from', 'on', 'which', 'and', 'was', 'him', 'he', 'up', 'down', 'out', 'you', 'about', 'then', 'his', 'toward', 'towards', 'in', 'top', 'at', 'its', 'like', 'as', 'because', 'under', 'an', 'that', 'those', 'these', 'to', 'said', 'this', 'is', 'yours', 'here', 'there', 'with', 'will', 'do', 'off', 'over', 'it', 'went', 'himself', 'too', 'but', 'has', 'hasnt', 'not', 'if', 'i', 'we', 'your', 'above', 'across', 'again', 'against', 'almost', 'along', 'also', 'around', 'are', 'am', 'another', 'any', 'been', 'be', 'back', 'away', 'before', 'behind', 'being', 'best', 'by', 'can', 'for', 'my', 'must', 'or', 'other', 'are', 'who', 'why', 'when', 'where', 'while', 'all', 'did', 'dont', 'had', 'go', 'get', 'im', 'into', 'after', 'could', 'her', 'have', 'me', 'no', 'now', 'says', 'mr', 'she', 'so', 'thier', 'them', 'they', 'were', 'what', 'some', 'would', 'always', 'among', 'us', 'even', 'ever', 'than', 'their', 'upon', 'very', 'how', 'say', 'hes', 'only', 'o', 'mrs', 'ours', 'through', 'de', 'mme', 'whom', 'once', 'one', 'without', 'asks', 'hed', 'well', 'thats', 'didnt', 'oh', 'ive', 'youre', 'doesnt', 'both', 'thats'];
return (strippedWords.indexOf(word.toLowerCase()) > -1);
},
//dynamically transforms the array of words into an object with count
wordsObject: function (array) {
var listObject = {};
for (idx in array) {
var word = array[idx];
if (listObject[word]) {
listObject[word] += 1;
} else {
listObject[word] = 1;
}
}
return listObject;
},
//strips all but the most used words
topWords: function (object, cutoff) {
var newObject = {};
for (word in object) {
//Change the number here for cutoff
if (object[word] > cutoff) {
newObject[word] = object[word];
}
}
return newObject;
}
}