Without appending the leftovers, the longer list loses its end.
Acceptance criteria
- 1.#out should show 1-2-3-4.
Without appending the leftovers, the longer list loses its end.
function merge(a, b) { const out = []; let i = 0, j = 0; while (i < a.length && j < b.length) { if (a[i] <= b[j]) out.push(a[i++]); else out.push(b[j++]); } return out; } document.querySelector('#out').textContent = merge([1, 3], [2, 4]).join("-");
Output ready when you are
Press Run to render your code, or Submit to validate your solution.