0% found this document useful (0 votes)
40 views1 page

Bubble Sort with Array Destructuring

The document contains a JavaScript function called bubbleSort that sorts an array using the bubble sort algorithm. It iterates through the array, comparing adjacent elements and swapping them if they are in the wrong order. The function returns the sorted array after completing the sorting process.

Uploaded by

Putri Santika Ms
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views1 page

Bubble Sort with Array Destructuring

The document contains a JavaScript function called bubbleSort that sorts an array using the bubble sort algorithm. It iterates through the array, comparing adjacent elements and swapping them if they are in the wrong order. The function returns the sorted array after completing the sorting process.

Uploaded by

Putri Santika Ms
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

function bubbleSort(array) {

for (let i = 0; i < [Link]; i++) {


for (let j = 0; j < [Link] - 1 - i; j++) {
if (array[j] > array[j + 1])
[array[j], array[j + 1]] = [array[j + 1], array[j]];
// Using ES6 array destructuring to swap
}
}
return array;
// Only change code above this line
}

bubbleSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);

You might also like