Files
KSP-MGA-Planner/dist/main/utilities/array.js
Krafpy 824af087c1 Modified file structure.
Modified the file structure to have the `index.html` at the root
of the repository. Needed for Github Pages.
2021-08-15 21:31:25 +02:00

26 lines
683 B
JavaScript

export function splitArrayInChunks(array, numChunks) {
const chunks = [];
const arrClone = array.slice();
for (let i = numChunks; i > 0; i--) {
chunks.push(arrClone.splice(0, Math.ceil(arrClone.length / i)));
}
return chunks;
}
export function mergeArrayChunks(array) {
const flat = [];
for (const chunk of array) {
for (const val of chunk) {
flat.push(val);
}
}
return flat;
}
export function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
const tmp = array[i];
array[i] = array[j];
array[j] = tmp;
}
}