I have a list of files like this :
['../page-1.png', '../page-3/png', '../page-2.png', '../page-6.png', ... '../page-9.png']
I need to sort these files according to the number at the end. I am using this :
imagePaths.sort((a, b) =>
a.toString().toLowerCase().compareTo(b.toString().toLowerCase()));
where imagePaths is the list of paths of those images.
THE ISSUE
This method works fine until there are only single digit file numbers, i.e. if there is a file called, '../page-10.png', it gets sorted into the list like so :
['../page-1.png', '../page-10.png', '../page-11.png', '../page-12.png', '../page-2.png', ..]
Now, how to sort them in their correct order?