Guest User

Untitled

a guest
Apr 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  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. };
Add Comment
Please, Sign In to add comment