mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-16 02:05:04 +01:00
19 lines
373 B
JavaScript
19 lines
373 B
JavaScript
export function chunk(arr, size) {
|
|
const chunks = [];
|
|
|
|
let index = 0;
|
|
while (index < arr.length) {
|
|
chunks.push(arr.slice(index, size + index));
|
|
index += size;
|
|
}
|
|
|
|
return chunks;
|
|
}
|
|
|
|
export function sortArrayByMap(arr, map = [], key) {
|
|
if (!arr) return [];
|
|
if (map.length === 0) return arr;
|
|
|
|
return map.map(id => arr.find(item => item[key] === id));
|
|
}
|