-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
46 lines (41 loc) · 1.04 KB
/
Copy pathutils.js
File metadata and controls
46 lines (41 loc) · 1.04 KB
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
42
43
44
45
46
/**
* Generates a single-dimensional array random numbers between start and stop
* size: the length of the array
*/
let provideRandNum = (start, stop, size) => {
let arr = [];
for(let i = 0; i < size; i++) {
let intermediate = start + Math.floor(Math.random() * (stop - start) + 0.5)
arr.push(intermediate)
}
return arr;
}
/**
* Generates a two-dimensional array random numbers between start and stop
* rowSize: the amount of rows
* colSize: the amount of values in each row
*/
let provideRandNum2D = (start, stop, rowSize, colSize) => {
let arr = [];
for(let i = 0; i < rowSize; i++) {
arr.push(provideRandNum(start, stop, colSize))
}
return arr
}
/**
* finds the maximum element in the arry
*/
let maximum = (arr) => {
let maximum = arr[0];
for(let i = 1; i < arr.length; i++) {
if (maximum < arr[i]) {
maximum = arr[i];
}
}
return maximum;
}
module.exports = {
"random1D": provideRandNum,
"random2D":provideRandNum2D,
"max":maximum
}