MCPcopy Create free account
hub / github.com/aiscript-dev/aiscript / merge

Function merge

src/interpreter/primitive-props.ts:324–342  ·  view source on GitHub ↗
(left: Value[], right: Value[], comp: VFn)

Source from the content-addressed store, hash-verified

322 return merge(left, right, comp);
323 };
324 const merge = async (left: Value[], right: Value[], comp: VFn): Promise<Value[]> => {
325 const result: Value[] = [];
326 let leftIndex = 0;
327 let rightIndex = 0;
328 while (leftIndex < left.length && rightIndex < right.length) {
329 const l = left[leftIndex]!;
330 const r = right[rightIndex]!;
331 const compValue = await opts.call(comp, [l, r]);
332 assertNumber(compValue);
333 if (compValue.value <= 0) {
334 result.push(left[leftIndex]!);
335 leftIndex++;
336 } else {
337 result.push(right[rightIndex]!);
338 rightIndex++;
339 }
340 }
341 return result.concat(left.slice(leftIndex)).concat(right.slice(rightIndex));
342 };
343
344 assertFunction(comp);
345 assertArray(target);

Callers 1

mergeSortFunction · 0.85

Calls 1

assertNumberFunction · 0.85

Tested by

no test coverage detected