-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.ts
39 lines (33 loc) · 786 Bytes
/
utils.ts
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
import { Vote } from "./types";
export function getTimeout() {
return getRandomIntInclusive(5000, 10000);
}
export function getRandomIntInclusive(min: number, max: number) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1) + min); // The maximum is inclusive and the minimum is inclusive
}
export function countTrue(array: boolean[]) {
let cnt = 0;
array.forEach((i) => {
if (i) {
cnt++;
}
});
return cnt;
}
export function countVotes(arr: Vote[]): {
trueCount: number;
falseCount: number;
} {
let trueCount = 0;
let falseCount = 0;
arr.forEach((obj) => {
if (obj.voteGranted === true) {
trueCount++;
} else {
falseCount++;
}
});
return { trueCount, falseCount };
}