Array.js
962 Bytes
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
module.exports = function(instance) {
instance.Array = {
map: function(array, func) {
var result = []
array.forEach(function(element) {
result.push(func(element))
})
return result
},
reject: function(array, func) {
var result = []
array.forEach(function(element) {
if(!func(element)) result.push(element)
})
return result
},
select: function(array, func) {
var result = []
array.forEach(function(element) {
if(func(element)) result.push(element)
})
return result
},
without: function(array, withouts) {
var result = []
array.forEach(function(e) {
if(withouts.indexOf(e) == -1) result.push(e)
})
return result
},
join: function(arr1, arr2) {
var result = []
arr1.forEach(function(e) { result.push(e) })
arr2.forEach(function(e) { result.push(e) })
return result
}
}
}