mirror of
https://github.com/tcsenpai/obsidiangarden_netlify.git
synced 2025-06-04 12:00:02 +00:00
Fix sorting order for numeric strings (#186)
This commit is contained in:
parent
40c2b78cf5
commit
0b9ecd7d20
@ -24,6 +24,17 @@ const sortTree = (unsorted) => {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Regular expression that extracts any initial decimal number
|
||||
const aNum = parseFloat(a.match(/^\d+(\.\d+)?/));
|
||||
const bNum = parseFloat(b.match(/^\d+(\.\d+)?/));
|
||||
|
||||
const a_is_num = !isNaN(aNum);
|
||||
const b_is_num = !isNaN(bNum);
|
||||
|
||||
if (a_is_num && b_is_num && aNum != bNum) {
|
||||
return aNum - bNum; //Fast comparison between numbers
|
||||
}
|
||||
|
||||
if (a.toLowerCase() > b.toLowerCase()) {
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user