Advertisement
CLooker

insertionSortRecur

Sep 28th, 2019
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const insert = ([ first, ...rest], item) =>
  2.   first === undefined
  3.     ? [ item ]
  4.     : item <= first
  5.     ? [ item, first, ...rest ]
  6.     : [ first, ...insert(rest, item)];
  7.  
  8. const insertionSort = items => items.reduce(insert, []);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement