Hello,
I dont understand why get an error
Can somebody help me with this issue ?
function bubbleSort(array) {
let sortedArray = array;
array.forEach((item, i) => {
if (array[i + 1]) {
if (item > array[i + 1]) {
sortedArray[i] = array[i + 1];
sortedArray[i + 1] = item;
bubbleSort(sortedArray)
}
}
});
return sortedArray
}
When I call
bubbleSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
I get the right result with is :
[1, 1, 2, 2, 4, 8, 32, 43, 43, 55, 63, 92, 123, 123, 234, 345, 5643]
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
.
Challenge: Implement Bubble Sort
Link to the challenge: