From 443b97a4caeb88d92899ffe49123cda489e06749 Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Tue, 29 Dec 2020 12:18:58 +0200 Subject: [PATCH] Update bubbleSort.md --- snippets/bubbleSort.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) 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; }; ```