-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
21 lines (18 loc) · 815 Bytes
/
index.ts
File metadata and controls
21 lines (18 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* eslint-disable no-magic-numbers */
import exceptKey from "@unction/exceptkey";
import attach from "@unction/attach";
import fresh from "@unction/fresh";
import length from "@unction/length";
import range from "@unction/range";
import reduceValues from "@unction/reducevalues";
const AFTER_PLACE = 1;
export default function shuffle<A> (orderedEnumerable: OrderedArray<A> | Set<A> | Record<string | number | symbol, B> | Map<B, A> | string) {
return reduceValues(([before, after]: [A, A]) => (value: A): OrderedArray<A> | Set<A> | Record<string | number | symbol, B> | Map<B, A> | string => {
const index = range(0)(length(before));
return [exceptKey(index)(before), attach(index)(value)(after)];
})(
[orderedEnumerable, fresh(orderedEnumerable)]
)(
orderedEnumerable
)[AFTER_PLACE];
}