-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
32 lines (28 loc) · 822 Bytes
/
utils.js
File metadata and controls
32 lines (28 loc) · 822 Bytes
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
const shuffleArray = (array) => {
const arrayCopy = array.slice(0);
return arrayCopy.sort(() => Math.random() - 0.5);
}
const createAsigneeList = (usernames, prCount) => {
const jobsPerUsername = split(prCount, usernames.length);
console.log(jobsPerUsername);
return shuffleArray(shuffleArray(usernames).flatMap((username, i) => Array(jobsPerUsername[i]).fill(username)));
}
const split = (number, parts) => {
if(number % parts === 0) {
return Array(parts).fill(number / parts);
} else {
const a = number % parts;
const b = (number - (number % parts)) / parts;
return [...Array(a).fill(b+1), ...Array(parts-a).fill(b)];
}
}
const wait = (ms) => {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
}
module.exports = {
shuffleArray,
createAsigneeList,
wait,
}