I need help sorting an unsorted array containing calculation results:
const solution = 955
const unsortedArray =
[
[["solution result cab"],[955.709]],
[["solution result abc"],[951.11]],
[["solution result cba"],[954.709]],
[["solution result bac"],[957.709]]
]
My goal is to sort the array based on the closest deviation from the solution:
[
[["solution result cab"],[955.709]],
[["solution result cba"],[954.709]],
[["solution result bac"],[957.709]],
[["solution result abc"],[951.11]]
]
Is there a way to implement range comparison in sort()
, or is there a more efficient solution?