I would like to return a new array made of arrays from an array of dictionaries that are to be sorted. I might not be explaining properly but I will just give examples of what I am trying todo.
So I have the following:
let foo = [{"id": "hello123"}, {"id":"goodbye123"}, {"id":"hello123"}];
I would like to sort it by the id value and return an array of array dictionary like so:
let bar = sortByKey(foo, "id");
console.log(bar);
output = [[{"id":"hello123"},{"id":"hello123"}],[{"id":"goodbye123"}]]
So far all I know how todo is sort it so that the outcome looks like:
[{"id":"hello123"},{"id":"hello123"},{"id":"goodbye123"}]
sortByKeyfunction? What is the code that you've tried that isn't working?sortByKeyfunction hasn't been made yet. currently using thisfoo.sort((a,b) => (a.id > b.id) ? 1 : ((b.id > a.id) ? -1 : 0));from another post to sort it by id's value.Array.reduceto make it more efficient