Update bubbleSort.md

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-12-29 12:18:58 +02:00
committed by GitHub
parent 3d6dc4bf40
commit 443b97a4ca

View File

@ -14,24 +14,17 @@ Sorts an array of numbers, using the bubble sort algorithm.
```js
const bubbleSort = arr => {
let swapped = false;
const a = [...arr];
for (let i = 1; i < a.length - 1; i++) {
swapped = false;
for (let j = 0; j < a.length - i; j++) {
if (a[j + 1] < a[j]) {
[a[j], a[j + 1]] = [a[j + 1], a[j]];
swapped = true;
}
}
if (!swapped) {
return a;
}
if (!swapped) return a;
}
return a;
};
```