-
Notifications
You must be signed in to change notification settings - Fork 0
/
algorithms.js
37 lines (31 loc) · 857 Bytes
/
algorithms.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
const Algorithms = {
phraseErrors: phrase => {
let splitted = phrase.split(" ");
let indexableSearch = "";
splitted.map((word, i) => {
let index = Algorithms.wordErrors(word);
indexableSearch =
indexableSearch +
(indexableSearch.length > 0 ? " " : indexableSearch) +
index;
});
return indexableSearch;
},
wordErrors: word => {
let splitted = word.split("");
let indexableSearch = "";
let indexableSuggest = "";
splitted.map((char, i) => {
const indexword = word.substr(i);
if (
indexword.length > 1 ||
(indexword.length === 1 && word).length === 1
) {
indexableSearch =
indexableSearch + (indexableSearch.length > 0 ? " " : "") + indexword;
}
});
return indexableSearch;
}
};
module.exports = Algorithms;