summaryrefslogtreecommitdiff
path: root/src/prelude/array.ts
diff options
context:
space:
mode:
authorAya Morisawa <AyaMorisawa4869@gmail.com>2018-09-06 02:16:08 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2018-09-06 02:16:08 +0900
commit395cfa61089efc4ab3ea1b6c6842521bad31efed (patch)
treeac26edc74619d701276f3e127c966878da807d5c /src/prelude/array.ts
parent互換性のためのコードを追加 & #2623 (diff)
downloadmisskey-395cfa61089efc4ab3ea1b6c6842521bad31efed.tar.gz
misskey-395cfa61089efc4ab3ea1b6c6842521bad31efed.tar.bz2
misskey-395cfa61089efc4ab3ea1b6c6842521bad31efed.zip
Resolve #2625 (#2627)
Diffstat (limited to 'src/prelude/array.ts')
-rw-r--r--src/prelude/array.ts7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/prelude/array.ts b/src/prelude/array.ts
new file mode 100644
index 0000000000..e944030a7f
--- /dev/null
+++ b/src/prelude/array.ts
@@ -0,0 +1,7 @@
+export function countIf<T>(f: (x: T) => boolean, xs: T[]): number {
+ return xs.filter(f).length;
+}
+
+export function count<T>(x: T, xs: T[]): number {
+ return countIf(y => x === y, xs);
+}