-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (33 loc) · 862 Bytes
/
index.js
File metadata and controls
41 lines (33 loc) · 862 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
33
34
35
36
37
38
39
40
41
const randomArray = []
const arrLength = (range) => {
return Math.floor(Math.random() * range) + 3
}
const arrValues = (minV, maxV) => {
return Math.floor(Math.random() * (maxV - minV)) - minV
}
const createRandomArray = (n, minV = 30, maxV = 500, cb = arrValues) => {
if (!Number.isInteger(n) || n <= 1) {
console.log('n must be an integer greater than 1.')
n = 10
}
if (!Number.isInteger(maxV)) {
console.log('maxV must be an integer.')
maxV = 500
}
if (!Number.isInteger(minV)) {
console.log('minV must be an integer.')
minV = 30
}
if (minV >= maxV) {
console.log('minV must be less than maxV.')
minV = 30
maxV = 500
}
let max = arrLength(n)
for (let i = 0; i < max; i++) {
let ran = cb(minV, maxV)
randomArray.push(ran)
}
return randomArray
}
module.exports = createRandomArray