Only count joined channels

This commit is contained in:
Ken-Håvard Lieng 2019-01-30 04:48:37 +01:00
parent 71bfe92dae
commit 3e90e6c86d
5 changed files with 178 additions and 154 deletions

View file

@ -170,7 +170,7 @@ export function measureScrollBarWidth() {
}
export function findIndex(arr, pred) {
if (!arr) {
if (!Array.isArray(arr) || typeof pred !== 'function') {
return -1;
}
@ -190,3 +190,17 @@ export function find(arr, pred) {
}
return null;
}
export function count(arr, pred) {
if (!Array.isArray(arr) || typeof pred !== 'function') {
return 0;
}
let c = 0;
for (let i = 0; i < arr.length; i++) {
if (pred(arr[i])) {
c++;
}
}
return c;
}