* feat(imageLoader):Add an nth image loader strategy (#10) * Updates for PR for nth menu * performance:Prior implementation was O(n^2), taking about 50 ms * feat:Nth image loader, added docs as requested
This commit is contained in:
1 parent
9a03bde0ae
commit
00e797801d
8 files changed
+212
-3
No files matched your search
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Interleave the items from all the lists so that the first items are first
|
||||
* in the returned list, the second items are next etc.
|
||||
* Does this in a O(n) fashion, and return lists[0] if there is only one list.
|
||||
*
|
||||
* @param {[]} lists
|
||||
* @returns [] reordered to be breadth first traversal of lists
|
||||
*/
|
||||
export default function interleave(lists) {
|
||||
if (!lists || !lists.length) return [];
|
||||
if (lists.length === 1) return lists[0];
|
||||
console.time('interleave');
|
||||
const useLists = [...lists];
|
||||
const ret = [];
|
||||
for (let i = 0; useLists.length > 0; i++) {
|
||||
for (const list of useLists) {
|
||||
if (i >= list.length) {
|
||||
useLists.splice(useLists.indexOf(list), 1);
|
||||
continue;
|
||||
}
|
||||
ret.push(list[i]);
|
||||
}
|
||||
}
|
||||
console.timeEnd('interleave');
|
||||
return ret;
|
||||
}
|
||||
Reference in new issue
Block a user