10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-11-04 05:03:53 +01:00

Add count Array extension

This commit is contained in:
Mickaël Véril 2020-09-29 11:29:40 +02:00
parent 7bfa5b6f03
commit 3088f44e9e

View File

@ -15,4 +15,23 @@ if (!Array.prototype.findAsync) {
}, []) }, [])
} }
} }
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)
}
}
} }