Update functional-tools.js

This commit is contained in:
Andros Fenollosa 2022-02-03 21:01:56 +01:00 committed by GitHub
parent af8a3ccd12
commit cba94e8740
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,3 +27,17 @@ function updateJSON(key, newValue, json) {
return jsonUpdate;
}, {});
}
/**
* Returns an array with a sequence.
*
* @param {number} start Beginning of the range.
* @param {number} stop End of range.
* @param {number} step Interval between numbers. Default is 1.
* @return {array}
*/
function range(start, stop=undefined, step=1) {
const startArray = stop === undefined ? 0 : start;
const stopArray = stop === undefined ? start : stop;
return Array.from({ length: (stopArray - startArray) / step + 1}, (_, i) => startArray + (i * step));
}