-
Notifications
You must be signed in to change notification settings - Fork 0
/
prelude.jang
62 lines (55 loc) · 1.04 KB
/
prelude.jang
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
List.contains = function(e) {
var i = 0;
var contained = false;
while (i < this.length()) {
if (this[i] == e) {
return true;
}
i += 1
};
return false;
};
List.find = function(e) {
var i = 0;
while (i < this.length()) {
if (this[i] == e) {
return i;
}
i += 1;
};
return -1;
};
List.any = function(f) {
var i = 0;
while (i < this.length()) {
if (f(this[i])) {
return true;
}
i += 1;
};
return false;
};
List.all = function(f) {
!(this.any(function(e) {!f(e)}))
};
List.forEach = function(f) {
var i = 0;
while(i < this.length()) {
f(this[i])
i += 1
}
}
List.map = function(f) {
var result = []
this.forEach(function(e) {
result.append(f(e))
})
return result
}
Object.ownItems = function() {
var that = this;
return this.items().filter(function(e) {e in that});
}
String.capitalize = function() {
return this[0].toUpper() + this[1:]
}