Skip to content

Commit e1b3871

Browse files
Change syntax for follow the pattern
1 parent 3b3d7b9 commit e1b3871

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/algorithms/sorting/gnome-sort/GnomeSort.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@ export default class GnomeSort extends Sort {
55
* @param {number[]} originalArray
66
*/
77
sort(originalArray) {
8+
const sortedArray = originalArray;
9+
810
// Variable that will be itering during loop
911
let index = 0;
1012

1113
// Loop for sort the array
1214
while (index < originalArray.length) {
1315
// Detects the first iteration
1416
if (index === 0) {
15-
index++;
17+
index += 1;
1618
}
1719

1820
// Detects if the current position is smaller of previous
1921
if (originalArray[index] >= originalArray[index - 1]) {
20-
index++;
22+
index += 1;
2123
} else {
2224
// Change the position of current position for before
23-
const temp = originalArray[index];
24-
originalArray[index] = originalArray[index - 1];
25-
originalArray[index - 1] = temp;
26-
index--;
25+
sortedArray[index] = originalArray[index - 1];
26+
sortedArray[index - 1] = originalArray[index];
27+
index -= 1;
2728
}
2829
}
2930

30-
const sortedArray = originalArray;
3131
return sortedArray;
3232
}
3333
}

0 commit comments

Comments
 (0)