-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path23-Day.js
29 lines (27 loc) · 975 Bytes
/
23-Day.js
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
function getRandomNumbersArray(length, delay) {
return new Promise((resolve, reject) => {
// Using setTimeout to simulate delay
setTimeout(() => {
// Creating an array of random numbers of specified length
const numbersArray = Array.from({ length }, () => Math.floor(Math.random() * 100));
// Resolving the promise with the generated array
resolve(numbersArray);
}, delay);
});
}
// Testing the function with delay of 2 seconds and array length of 5
getRandomNumbersArray(5, 2000)
.then((result) => {
console.log(result); // Output: [23, 74, 48, 52, 63]
})
.catch((error) => {
console.error(error);
});
// Testing the function with delay of 3 seconds and array length of 10
getRandomNumbersArray(10, 3000)
.then((result) => {
console.log(result); // Output: [79, 5, 64, 46, 2, 55, 33, 71, 28, 38]
})
.catch((error) => {
console.error(error);
});