I have 2 arrays
a = [2,3,1,4]
b = [{id: 1}, {id: 2}, {id: 3}, {id: 4}]
How do I get b sorted based on a? My desir
Here's an alternative construction using Ramda that might be a bit more succinct, and the functions are pretty easy to repurpose for other things.
const {indexBy, prop, map, flip} = R
const a = [2,3,1,4]
const b = [{id: 1}, {id: 2}, {id: 3}, {id: 4}]
const toIndexById = indexBy(prop('id'))
const findIndexIn = flip(prop)
const c = map(findIndexIn(toIndexById(b)), a)
console.log(c)