-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdataToArray.js
34 lines (29 loc) · 1.02 KB
/
dataToArray.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
30
31
32
33
34
// --------------------------------------------------------------------------
// -- dataToArray.js
// -- initial author: Renick Bell ([email protected])
// -- initial creation date: Wed Jun 28 10:08:48 AM CST 2023
// -- contributors: Yiler Huang ([email protected]); Steve Wang ([email protected])
// -- license: GPL 3.0
// --------------------------------------------------------------------------
function buildArray(n, fillFunction) {
return Array.from({ length: n }, (_, i) => fillFunction(i));
}
// modify so that it doesn't have crash potential
function linearArray(start, step, numberOfSteps) {
let output = this.buildArray(numberOfSteps, (i) => start + i * step);
return output;
}
function integerArray(start, end) {
return this.linearArray(start, 1, end);
}
function geometricArray(start, step, numberOfSteps) {
let output = this.buildArray(numberOfSteps, (i) => i * step);
output[0] = start;
return output;
}
module.exports = {
buildArray,
linearArray,
integerArray,
geometricArray,
};