The functionality of the insertion sort seems to be malfunctioning with this error message: An issue occurred as a function is taking longer than expected to execute. Are there any errors present in your code?
// Code snippet for insertion sort
var insert = function(array, rightIndex, value) {
for(var j = rightIndex;
j >= 0 && array[j] > value;
j--)
{
array[j + 1] = array[j];
}
array[j + 1] = value;
};
var insertionSort = function(array) {
for(var i = 0; i < array.length ; i++)
{
insert(array,i,array[i+1]);
}
};
var array = [22, 11, 99, 88, 9, 7, 42];
insertionSort(array);
println("Array after sorting: " + array);
Program.assertEqual(array, [7, 9, 11, 22, 42, 88, 99]);