Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 133x 1x 132x 1x 131x 131x 131x 131x 150x 150x 150x 131x | import defined from "./defined.js";
import DeveloperError from "./DeveloperError.js";
/**
* Subdivides an array into a number of smaller, equal sized arrays.
*
* @function subdivideArray
*
* @param {Array} array The array to divide.
* @param {number} numberOfArrays The number of arrays to divide the provided array into.
*
* @exception {DeveloperError} numberOfArrays must be greater than 0.
*/
function subdivideArray(array, numberOfArrays) {
//>>includeStart('debug', pragmas.debug);
if (!defined(array)) {
throw new DeveloperError("array is required.");
}
if (!defined(numberOfArrays) || numberOfArrays < 1) {
throw new DeveloperError("numberOfArrays must be greater than 0.");
}
//>>includeEnd('debug');
const result = [];
const len = array.length;
let i = 0;
while (i < len) {
const size = Math.ceil((len - i) / numberOfArrays--);
result.push(array.slice(i, i + size));
i += size;
}
return result;
}
export default subdivideArray;
|