Last active
November 14, 2018 12:40
-
-
Save Berkmann18/10c937d793f5eeb5443681cdf6ff9881 to your computer and use it in GitHub Desktop.
Stress test helpers for arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @description Generate indexes used to access an array. | |
* @param {number} len Length of the array | |
* @param {number} [bound=1] How much the boundaries needs to be extended by | |
* @param {number} [mult=1] How the resulting array of index needs to be multiplied by | |
* @returns {number[]} Array of indexes | |
* @example | |
* let arr = ['lorem', 'ipsum', 'dolore']; | |
* genIdxs(arr.length); //[-4, -3, -2, -1, 0, 1, 2, 3, 4] | |
* genIdxs(arr.length, 2); //[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5] | |
* genIdxs(arr.length, 1, 2); //[-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8] | |
*/ | |
const genIdxs = (len, bound = 1, mult = 1) => { | |
let res = [], | |
HB = (len + bound) * mult; | |
for (let i = -HB; i <= HB; ++i) res.push(i); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment