I was trying to sort an array of objects containing around 100 large entities (having almost 30 keys ) on the basis of values of key which were deeply nested within an object and for that I was using lodash's orderBy method:
let name = (user) => user.accountDetails.name.toLowerCase();
let dob = (user) => user.personalProfile.dob;
orderBy(cloneDeep(data), [name, dob], [sortOrder1, sortOrder2])
*considering sortOrder to be either desc or asec
But the time taken by the sort process is pretty large. What kind of faster approach we can use to sort the array of objects with the keys buried deep within the object?
Example data (consider 50 entries like these having 40 keys at least)
{
"list": "bugs42",
"start-date": "2015-08-27",
"accountDetails": {
"name": "diamond",
"text": "8 months",
"milliseconds": 19936427304
}
"personalProfile": {
"name": "stark",
"dob": "2003-03-12T09:26:39.980Z",
}
},
{
"list": "bugs50",
"start-date": "2015-08-27",
"accountDetails": {
"name": "ruby",
"text": "8 months",
"milliseconds": 19936427305
}
"personalProfile": {
"name": "warmachine",
"dob": "2007-03-31T09:26:39.980Z",
}
}