Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Insertion sort
- * @param {array} arr - Array of numbers
- */
- const insertionSort = (arr = []) => {
- const length = arr.length;
- for (let i = 1; i < length; i++) {
- const item = arr[i];
- let j = i - 1;
- while (j >= 0 && arr[j] > item) {
- arr[j + 1] = arr[j];
- arr[j] = item;
- j--;
- }
- }
- };
Add Comment
Please, Sign In to add comment