You are viewing a single comment's thread. Return to all comments →
-- JavaScript --
function countSort(arr) { // Write your code here const obj = {}; const mid = arr.length / 2; arr.forEach((e, i) => { if (i < mid) { if (obj[e[0]]) obj[e[0]].push('-'); else obj[e[0]] = ['-'] return } if (obj[e[0]]) obj[e[0]].push(e[1]) else obj[e[0]] = [e[1]] }) console.log(Object.values(obj).map((e) => e.join(' ')).join(' ')); }
The Full Counting Sort
You are viewing a single comment's thread. Return to all comments →
-- JavaScript --