This repository was archived by the owner on Jul 6, 2023. It is now read-only.
forked from DoctorLai/SteemWitnessAutoSwitch
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfunctions.js
More file actions
47 lines (43 loc) · 1.19 KB
/
functions.js
File metadata and controls
47 lines (43 loc) · 1.19 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
module.exports.sleep = function(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
module.exports.log = function (msg) {
console.log(new Date().toISOString().replace("T", " ").substr(0, 19), msg);
}
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) {
var 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;
}