I want to sort an array of arrays based on:
- Parameter given manually
- Then sorted by DESC
Here is the array
var ar = [
[{'name' : 'b', 'val' : '1'}, {'name' : 'b', 'val' : '10'}], // 'name' are always the same
[{'name' : 'a', 'val' : '2'}, {'name' : 'a', 'val' : '2'}],
[{'name' : 'c'}, {'name' : 'c', 'val' : '100'}]
]
When the sorting function is executed: sortBy('a')
It should return me:
var ar = [
[{'name' : 'a', 'val' : '2'}, {'name' : 'a', 'val' : '2'}],
[{'name' : 'c'}, {'name' : 'c', 'val' : '100'}]
[{'name' : 'b', 'val' : '1'}, {'name' : 'b', 'val' : '10'}],
]
Because 'a' is given as a parameter, it has priority. Then it is sorted from Z to A.
Solution should be written is ES5 (using lodash if possible).
[<>]snippet editor.