summaryrefslogtreecommitdiff
path: root/src/prelude/array.ts
diff options
context:
space:
mode:
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);
+}