1function insertionSort(arr) {
2 const a = [...arr];
3 const n = a.length;
4 for (let i = 1; i < n; i++) {
5 const key = a[i];
6 let j = i - 1;
7 while (j >= 0 && a[j] > key) {
8 a[j + 1] = a[j];
9 j--;
10 }
11 a[j + 1] = key;
12 }
13 return a;
14}