2020-09-21 17:03:10 +02:00
|
|
|
if (!Array.prototype.findAsync) {
|
2020-09-24 16:53:11 +02:00
|
|
|
Array.prototype.findAsync = async function (asyncCallback) {
|
2020-09-21 17:03:10 +02:00
|
|
|
for (const item of this) {
|
|
|
|
if (await asyncCallback(item)) {
|
|
|
|
return item
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-24 16:56:51 +02:00
|
|
|
if (!Array.prototype.findAllIndexes) {
|
|
|
|
Array.prototype.findAllIndexes = function (Callback) {
|
2020-09-24 18:38:45 +02:00
|
|
|
return this.reduce(function(a, e, i) {
|
2020-09-24 16:56:51 +02:00
|
|
|
if (Callback(e))
|
|
|
|
a.push(i)
|
|
|
|
return a
|
|
|
|
}, [])
|
|
|
|
}
|
|
|
|
}
|
2020-09-29 11:29:40 +02:00
|
|
|
if (!Array.prototype.count) {
|
|
|
|
Array.prototype.count = function (o) {
|
|
|
|
var callback
|
|
|
|
var item
|
|
|
|
if (typeof o==="function") {
|
|
|
|
callback=o
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
callback=(e)=>item==e
|
|
|
|
}
|
|
|
|
return this.reduce(function(c, e, i) {
|
|
|
|
if (callback) {
|
|
|
|
if (callback(e))
|
|
|
|
c++
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
},0)
|
|
|
|
}
|
|
|
|
}
|
2020-09-21 17:03:10 +02:00
|
|
|
}
|