diff --git a/snippets/bubbleSort.md b/snippets/bubbleSort.md index 8e0396284..c3126a3a0 100644 --- a/snippets/bubbleSort.md +++ b/snippets/bubbleSort.md @@ -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; }; ```