Insertion Sort
12345678910111213141516
const input = [99, 44, 6, 2, 1, 5, 63, 87, 283, 4, 0];
const insertionSort = (a) => {
for (let i = 1; i < a.length; i++) {
let temp = a[i];
for (let j = i; j > 0; j--) {
if (temp < a[j - 1]) {
a[j] = a[j - 1];
a[j - 1] = temp;
}
}
}
return a;
};
console.log(insertionSort(input));
JavaScript
INFO