update reduce and examples

This commit is contained in:
Quentin Leonetti
2019-07-18 10:54:13 +02:00
parent 521ece7937
commit 50e13e932d
3 changed files with 17 additions and 9 deletions

View File

@@ -90,8 +90,13 @@ function Library (ronin) {
})
}
this.reduce = (fn, arr, acc = 0) => {
return arr.reduce(fn, acc)
this.reduce = async (fn, arr, acc) => {
const length = arr.length
let result = acc === undefined ? subject[0] : acc
for (let i = acc === undefined ? 1 : 0; i < length; i++) {
result = await fn(result, arr[i], i, arr)
}
return result;
}
this.len = (item) => {