Skip to content

Commit c33f233

Browse files
authored
Merge pull request #79 from opensource9ja/bug/sorting
Bug in sorting
2 parents dbf3e7e + b7198a4 commit c33f233

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

danfojs/src/core/utils.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -663,15 +663,22 @@ export class Utils {
663663
}
664664

665665
__sort(arr, ascending = true) {
666-
667-
let collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
668666
let sorted = arr.slice();
669-
670-
if (ascending) {
671-
return sorted.sort(collator.compare);
672-
} else {
673-
return sorted.sort((a, b) => collator.compare(b, a));
674-
}
667+
return sorted.sort((a, b) => {
668+
if (ascending) {
669+
if ((typeof a === "string") && typeof b === "string") {
670+
return a.charCodeAt() - b.charCodeAt();
671+
} else {
672+
return a - b;
673+
}
674+
} else {
675+
if ((typeof a === "string") && typeof b === "string") {
676+
return b.charCodeAt() - a.charCodeAt();
677+
} else {
678+
return b - a;
679+
}
680+
}
681+
});
675682

676683

677684
}

0 commit comments

Comments
 (0)