I need to sort an array of objects by their values.
Provided Input
let arr = ['4-5', 'null-4', '7-null', '1-2']
Desired Output
['null-4', '1-2', '4-5','7-null']
I attempted to utilize string.localCompare()
in combination with value.split('-')
, but it seemed to impact performance negatively. Then I experimented with Intl.Compare
, however, the resulting order was
['null-4','7-null', '1-2', '4-5']
.
Is there a way to achieve the desired output using Intl.Compare
?