mirror of
https://github.com/LCPQ/QUESTDB_website.git
synced 2024-08-25 13:41:50 +02:00
Add count Array extension
This commit is contained in:
parent
7bfa5b6f03
commit
3088f44e9e
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user