-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstem.js
More file actions
43 lines (41 loc) · 1.3 KB
/
Copy pathstem.js
File metadata and controls
43 lines (41 loc) · 1.3 KB
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
var stems = require('./stems.json');
var stem = function (arr) {
var outArr = []; //output array
var found = false;
for(var i = 0; i < arr.length; i++) {
//check if items contain a stem
for(var k = 0; k < stems.length; k++) {
var obj = stems[k];
var index = arr[i].indexOf(obj.content);
var contentLength = obj.content.length;
console.log(arr[i]);
var string = arr[i];
if(index != -1) {
//if the char at for string + length is a char
if(string.charAt(index + contentLength) == "") {
found = true;
//stem
//string = string.substring(0, index);
//if the stem is not already in
if (outArr.indexOf(string) == -1) {
//add to the array
outArr.push(string);
break;
}
}
}
}
//stem was not found
if(found == false) {
//add only if not found
if(outArr.indexOf(string) == -1) {
outArr.push(string);
}
}
else {
found = false;
}
}
return outArr;
}
module.exports = stem;