I have an array returned by a REST
query that represents the number of items in a multi-step production process.
var steps = [
{ name:'Package', value:3},
{ name:'Assemble', value:1 },
{ name:'Ship', value:7},
{ name:'Preprocess', value:9 },
{ name:'Paint', value:5 }
];
I'd like to sort them in the order of the process, like this:
- Preprocess
- Paint
- Assemble
- Package
- Ship
I have other alphanumeric sorts that I am doing with Underscore but I cannot figure this one out.
You could take an object for the wanted order with numerical values for the position. Then sort by this values.
You can create an object which mentions the priority on each name while ordering.
I'm just using a precedence map for every step type so that I can use it in the compare function.