My task involves sorting an array of strings:
['1.2.3', '1.5.2', '1.23', '1.20.31']
I am looking for a way to sort the array by splitting each string separated by dots, such as 1.2.3
into ['1','2', '3']
, and then comparing them position by position similar to Python tuple comparison.
The expected result should be:
['1.2.3', '1.5.2' '1.20.31', '1.23']
I am aware that this can be achieved using native JavaScript's .sort
method with a custom comparison function. However, I am unable to modify the original array. Is there a way to accomplish this using Lodash's _.sortBy
which requires a key function?