Skip to content

Commit a8e7286

Browse files
author
wakidurrahman
committed
feat: refactor
1 parent 181e14b commit a8e7286

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/code-challenges/bubble-sort.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66

77
// Normal
88
function bubbleSortVariationNormal(arr) {
9+
const len = arr.length - 1;
910
let swaps;
1011
do {
1112
swaps = false;
12-
for (let i = 0; i < arr.length - 1; i++) {
13-
const element = arr[i];
14-
console.log(element);
13+
for (let i = 0; i < len; i++) {
1514
if (arr[i] > arr[i + 1]) {
1615
// start with the first two elements and sort them in ascending order. (Compare the element to check which one is greater).
1716
let temp = arr[i + 1]; // store second element for swap

0 commit comments

Comments
 (0)