Skip to content

Commit 2b36d72

Browse files
Merge pull request #2 from jakubrb/main
fix wrong sorting check
2 parents 2fdedd6 + 9e94187 commit 2b36d72

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

scripts/arrayFunctions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function randomizePositions(array, timesToSwap = array.length) {
88
}
99

1010
function isSorted(array) {
11-
const sortedArray = [...array].sort((a,b)=>a>b);
11+
const sortedArray = [...array].sort((a,b)=>a-b);
1212
let sorted = true;
1313
array.forEach((element, index) => {
1414
if (element !== sortedArray[index]) {

scripts/randomSort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class RandomSort extends Sort {
1515
cnt.fillStyle = "#000";
1616
cnt.fillRect(0, 0, cnt.canvas.width, cnt.canvas.height);
1717
const sizeOfBlock = cnt.canvas.width / arrayToSort.length;
18-
const sortedArray = [...arrayToSort].sort();
18+
const sortedArray = [...arrayToSort].sort((a,b)=>a-b);
1919
arrayToSort.forEach((element, index) => {
2020
if (element === sortedArray[index]) {
2121
cnt.fillStyle = "#55b809";

scripts/visualSortCheck.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class SortChecking extends Sort {
1515
cnt.fillStyle = "#000";
1616
cnt.fillRect(0, 0, cnt.canvas.width, cnt.canvas.height);
1717
const sizeOfBlock = cnt.canvas.width / arrayToSort.length;
18-
const sortedArray = [...arrayToSort].sort((a,b)=>a>b);
18+
const sortedArray = [...arrayToSort].sort((a,b)=>a-b);
1919
arrayToSort.forEach((element, index) => {
2020
if (this.checkIndex === arrayToSort.length - 1) {
2121
cnt.fillStyle = getColorBasedOnValue(element);

0 commit comments

Comments
 (0)