-
Notifications
You must be signed in to change notification settings - Fork 2
/
proto.js
72 lines (68 loc) · 1.87 KB
/
proto.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Array.prototype.cancelCharacters = function (characters) {
let words = this;
var result = [];
for (var i = 0; i < words.length; i++) {
var word = words[i];
var isCanceled = false;
for (var j = 0; j < characters.length; j++) {
var character = characters[j];
if (word.includes(character)) {
isCanceled = true;
break;
}
}
if (!isCanceled) {
result.push(word);
}
}
return result;
};
Array.prototype.withCharactersButNotInIndex = function (characters, index) {
let words = this;
var result = [];
for (var i = 0; i < words.length; i++) {
var word = words[i];
var isPresent = false;
for (var j = 0; j < characters.length; j++) {
var character = characters[j];
if (word.includes(character) && word[index] != character) {
isPresent = true;
break;
}
}
if (isPresent) {
result.push(word);
}
}
return result;
};
Array.prototype.withCharacters = function (characters) {
let words = this;
var result = [];
for (var i = 0; i < words.length; i++) {
var word = words[i];
var isPresent = false;
for (var j = 0; j < characters.length; j++) {
var character = characters[j];
if (word.includes(character)) {
isPresent = true;
break;
}
}
if (isPresent) {
result.push(word);
}
}
return result;
};
Array.prototype.withCharAndIndex = function (character, index) {
let words = this;
var result = [];
for (var i = 0; i < words.length; i++) {
var word = words[i];
if (word[index] == character) {
result.push(word);
}
}
return result;
}