-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice.js
More file actions
27 lines (24 loc) · 871 Bytes
/
service.js
File metadata and controls
27 lines (24 loc) · 871 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
const { workerData, parentPort } = require('worker_threads')
const generateArray = (min, max) => {
let arrayContainer = [];
const genNum = Math.floor(Math.random() * (max - min + 1) + min);
arrayContainer.push(genNum);
console.time();
for (let counter = 0; counter < 4; counter++) {
let newGen = Math.floor(Math.random() * (max - min + 1) + min);
while (arrayContainer.lastIndexOf(newGen) !== -1) {
newGen = Math.floor(Math.random() * (max - min + 1) + min);
}
arrayContainer.push(newGen);
}
console.timeEnd();
return arrayContainer;
};
setTimeout(() => {
let b = generateArray(1, 15);
let i = generateArray(16, 30);
let n = generateArray(31, 45);
let g = generateArray(46, 60);
let o = generateArray(61, 75);
parentPort.postMessage({ b, i, n, g, o })
}, workerData);