umami/lib/array.js

19 lines
373 B
JavaScript
Raw Normal View History

2020-09-13 10:26:54 +02:00
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;
}
2022-08-05 06:37:18 +02:00
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));
}