I'm trying to sort a list of objects based on the appearance of a key in an external object. For some reason, I'm not able to sort the array and I tried using lodash or other methods..
Here's a more simple example:
arr = [1, 2, 3, 4, 5, 6]
obj = { 4: true, 6: true }
arr.sort((a, b) => obj[a] - obj[b])
// [1, 2, 3, 4, 5, 6]
I would like the truth-y values to be first, as in [4, 6, 1, 2, 3, 5]
Why doesn't this work?