Drop Promises for map and filter
This commit is contained in:
parent
e375668143
commit
4d0df33005
@ -424,18 +424,12 @@ function Library (client) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.map = (arr, fn) => { // Run a function on each element in a list.
|
this.map = (arr, fn) => { // Returns a new list with fn applied to each value.
|
||||||
return Promise.all(arr.map(fn)).then(result => { return result })
|
return arr.map(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.filter = (arr, fn) => { // Remove from list, when function returns false.
|
this.filter = (arr, fn) => { // Returns a new list, without values evaluated to false by fn.
|
||||||
const list = Array.from(arr)
|
return arr.filter(fn);
|
||||||
return Promise.all(list.map((element, index) => fn(element, index, list)))
|
|
||||||
.then(result => {
|
|
||||||
return list.filter((_, index) => {
|
|
||||||
return result[index]
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.reduce = (arr, fn, acc) => {
|
this.reduce = (arr, fn, acc) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user