summaryrefslogtreecommitdiff
path: root/src/prelude/array.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-09-06 04:28:42 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-09-06 04:28:42 +0900
commitccf8e44acc8b4bcdb19895ce60cd86d699efcbf7 (patch)
treec313e84c98b54934ef0f24922610ff5e0f60a751 /src/prelude/array.ts
parentImprove welcome page (diff)
parentShow host in local user detail (#2634) (diff)
downloadmisskey-ccf8e44acc8b4bcdb19895ce60cd86d699efcbf7.tar.gz
misskey-ccf8e44acc8b4bcdb19895ce60cd86d699efcbf7.tar.bz2
misskey-ccf8e44acc8b4bcdb19895ce60cd86d699efcbf7.zip
Merge branch 'develop' of https://github.com/syuilo/misskey into develop
Diffstat (limited to 'src/prelude/array.ts')
-rw-r--r--src/prelude/array.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/prelude/array.ts b/src/prelude/array.ts
new file mode 100644
index 0000000000..aee17640ed
--- /dev/null
+++ b/src/prelude/array.ts
@@ -0,0 +1,11 @@
+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);
+}
+
+export function intersperse<T>(sep: T, xs: T[]): T[] {
+ return [].concat(...xs.map(x => [sep, x])).slice(1);
+}