We're a place where coders share, stay up-to-date and grow their careers.
const partion = (n) => (list) => Array(n).fill(0).map((_, i) => list.slice(i * (Math.ceil(list.length / n)), (i + 1) * Math.ceil(list.length / n))); const merge = ([list1, list2]) => list1.flatMap((n, i) => [n, list2[i]]).filter(Boolean); const waveSort = (list) => list.sort((a, b) => a - b) |> partion(2) |> merge;
Discussion on: Daily Challenge #308 - Wave Sort