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

Function mergeSort

src/interpreter/primitive-props.ts:316–323  ·  view source on GitHub ↗
(arr: Value[], comp: VFn)

Source from the content-addressed store, hash-verified

314 }),
315 sort: (target: VArr): VFn => FN_NATIVE(async ([comp], opts) => {
316 const mergeSort = async (arr: Value[], comp: VFn): Promise<Value[]> => {
317 if (arr.length <= 1) return arr;
318 const mid = Math.floor(arr.length / 2);
319 const left_promise = mergeSort(arr.slice(0, mid), comp);
320 const right_promise = mergeSort(arr.slice(mid), comp);
321 const [left, right] = await Promise.all([left_promise, right_promise]);
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;

Callers 1

primitive-props.tsFile · 0.85

Calls 1

mergeFunction · 0.85

Tested by

no test coverage detected