-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathutils.js
More file actions
46 lines (37 loc) · 1.29 KB
/
utils.js
File metadata and controls
46 lines (37 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
export function shuffle(list) {
for (let i = list.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[list[i], list[j]] = [list[j], list[i]];
}
}
export function interval(a, b, mapfunction) {
if (mapfunction)
return new Array(b - a + 1).fill(0).map((el, index) => mapfunction(a + index));
return new Array(b - a + 1).fill(0).map((el, index) => a + index);
}
export function matrixInterval(a, b, c, d, mapfunction) {
return interval(c, d, (y) => interval(a, b, (x) => mapfunction(x, y))).flat(1);
}
export function disjoint(list1, list2) {
return list1.every((a) => list2.every((b) => a.toString() != b.toString()));
}
export function remove(element, list) {
const i = list.findIndex((search) => search.toString() == element.toString());
list.splice(i, 1);
}
export function randEl(list) {
const index = Math.floor(Math.random() * list.length);
return list[index];
}
export function sleep(milliseconds) {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
}
export function writeStatus(txt) {
$("#statusText").html(txt);
}
export function tileAt(coord) {
return $(`.tile[coord="${coord.toString()}"]`);
}
export function tileFrontAt(coord) {
return $(`.tileFront[coord="${coord.toString()}"]`);
}