UNPKG

spica

Version:

Supervisor, Coroutine, Channel, select, AtomicPromise, Cancellation, Cache, List, Queue, Stack, and some utils.

14 lines (13 loc) 448 B
export function sort<T>(as: T[], cmp: (a: T, b: T) => number, times: number, debug = false): T[] { if (!debug && times * times > as.length * 1.25) return as.sort(cmp); times = times < as.length - 1 ? times : as.length - 1; for (let i = 0; i < times; ++i) { for (let j = i + 1; j < as.length; ++j) { if (cmp(as[i], as[j]) > 0 === false) continue; const a = as[i]; as[i] = as[j]; as[j] = a; } } return as; }