Given an object like:
accounts = [
{ bankType: "Checking", currency: "USD", amount: 123.45 },
{ bankType: "Saving", currency: "CAD", amount: 1.95 },
{ bankType: "Saving", currency: "USD", amount: 23.31 },
{ bankType: "Checking", currency: "CAD", amount: 1953.1 },
];
How do I sort by the objects properties in the array where bankType of "Checkings" are sorted first then currency of "CAD" accounts are sorted next to achieve the following result below?
// Sorted array of objects result
[
{ bankType: "Checking", currency: "CAD", amount: 1953.1 },
{ bankType: "Checking", currency: "USD", amount: 123.45 },
{ bankType: "Saving", currency: "CAD", amount: 1.95 },
{ bankType: "Saving", currency: "USD", amount: 23.31 },
];
The problem isn't about sorting it alphabetically using the built-in localeCompare function, the problem lies in having to sort by specific constant value of Checking first then by CAD second.