TGViewer
JavaScript JavaScript @javascript · 31.1K subscribers
Post #2699 4K
CHALLENGE

function mystery(arr, depth = 0) {
if (arr.length <= 1) return arr;

const mid = Math.floor(arr.length / 2);
const left = mystery(arr.slice(0, mid), depth + 1);
const right = mystery(arr.slice(mid), depth + 1);

const result = [];
let i = 0, j = 0;

while (i < left.length && j < right.length) {
result.push(left[i] <= right[j] ? left[i++] : right[j++]);
}

return result.concat(left.slice(i)).concat(right.slice(j));
}

const arr = [3, 1, 4, 1, 5];
console.log(mystery(arr));
  • ❤ 6
More from @javascript
  1. Sep 30, 2026Post #3528
  2. Sep 30, 2026CHALLENGE const message = 'a😀bc'; const codePoints = [...message]; const combined = { raw…
  3. Sep 29, 2026Post #3526
  4. Sep 29, 2026CHALLENGE const order = []; order.push('start'); setTimeout(() => { order.push('timeout');…
  5. Sep 28, 2026Post #3524
  6. Sep 28, 2026CHALLENGE let order = []; function a() { try { return 'try'; } finally { order.push('a-fin…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →