daily pastebin goal
39%
SHARE
TWEET

Untitled

a guest Apr 23rd, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Insertion sort
  3.  * @param {array} arr - Array of numbers
  4.  */
  5. const insertionSort = (arr = []) => {
  6.   const length = arr.length;
  7.  
  8.   for (let i = 1; i < length; i++) {
  9.     const item = arr[i];
  10.     let j = i - 1;
  11.  
  12.     while (j >= 0 && arr[j] > item) {
  13.       arr[j + 1] = arr[j];
  14.       arr[j] = item;
  15.       j--;
  16.     }
  17.   }
  18. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top