-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathfunctions.js
More file actions
50 lines (46 loc) · 1.24 KB
/
Copy pathfunctions.js
File metadata and controls
50 lines (46 loc) · 1.24 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
47
48
49
50
module.exports.sleep = function (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
module.exports.log = function (messages) {
// Get the current timestamp
const timestamp = new Date().toISOString();
// Format the messages with the timestamp
console.log(`[${timestamp}]`, ...messages);
}
module.exports.runInterval = function (func, wait, times) {
let interv = function (w, t) {
return function () {
if (typeof t === "undefined" || t-- > 0) {
setTimeout(interv, w);
try {
func.call(null);
}
catch (e) {
t = 0;
throw e.toString();
}
}
};
}(wait, times);
setTimeout(interv, wait);
};
// check if y array includes any x
module.exports.arrayInArray = function (x, y) {
if (!x) { return false; }
if (!y) { return false; }
if (!x.constructor === Array) return false;
if (!y.constructor === Array) return false;
if (typeof x !== "object") { return false; }
if (!Array.isArray(x)) { return false; }
return x.some(r => y.includes(r));
}
module.exports.shuffle = function (a) {
let j, x, i;
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
x = a[i];
a[i] = a[j];
a[j] = x;
}
return a;
}