mirror of
https://github.com/Krafpy/KSP-MGA-Planner.git
synced 2025-12-05 20:40:13 -08:00
Modified the file structure to have the `index.html` at the root of the repository. Needed for Github Pages.
26 lines
683 B
JavaScript
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;
|
|
}
|
|
}
|