DEV Community

Discussion on: Daily Challenge #308 - Wave Sort

Collapse
 
alfredosalzillo profile image
Alfredo Salzillo
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;
Enter fullscreen mode Exit fullscreen mode