From 3088f44e9eca4e9d61b96092321aa70f1411454d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20V=C3=A9ril?= Date: Tue, 29 Sep 2020 11:29:40 +0200 Subject: [PATCH] Add count Array extension --- static/js/ArrayExtensions.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/static/js/ArrayExtensions.js b/static/js/ArrayExtensions.js index e926bc35..bd40f8cb 100644 --- a/static/js/ArrayExtensions.js +++ b/static/js/ArrayExtensions.js @@ -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) + } + } } \ No newline at end of file