i want to ask about array.sort() was looking for solution about this kind of problem how to sort a array with this kind of structure
array.sort((a, b) => a.foo.foo1.foo2 - b.foo.foo1.foo2)
where this working but after rewrite the code for multiple use case
export const handleSort = (arr, sortBy, desc) => {
arr = [...arr];
if (desc) {
return arr.sort((a, b) => b[sortBy] - a[sortBy]);
} else {
return arr.sort((a, b) => a[sortBy] - b[sortBy]);
}
later on if i need like
return arr.sort((a, b) => b[sortBy][0][1] - a[sortBy][0][1]);
i cant use this