You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i need see arr object what happening with debuging
function insertionSort(arr) {
// Traverse through 1 to arr.length
for (let i = 1; i < arr.length; i++) {
// Current element to be inserted in the sorted portion
let key = arr[i];
// Move elements of arr[0..i-1] that are greater than key
// to one position ahead of their current position
let j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j--;
}
// Place the key in its correct position
arr[j + 1] = key;
}
return arr;
}
// Example usage
const exampleArray = [64, 34, 25, 12, 22, 11, 90];
console.log("Original array:", exampleArray);
const sortedArray = insertionSort(exampleArray);