How to sort an array using Array.prototype.sort() by type and currency in this order:
debit => credit => external => loan
and if there are several currencies in the same type, then arrange in this order:
RUB => USD => EUR => GBP
I understand how to use sort () with numbers, but I don’t understand how to do such sorting.
const accounts = [
{ id: 1, type: 'credit', currency: 'GBP' },
{ id: 2, type: 'debit', currency: 'EUR' },
{ id: 3, type: 'loan' },
{ id: 4, type: 'credit', currency: 'RUB' },
{ id: 5, type: 'credit', currency: 'RUB' },
{ id: 6, type: 'debit', currency: 'USD' },
{ id: 7, type: 'debit', currency: 'RUB' },
{ id: 8, type: 'external' },
{ id: 9, type: 'credit', currency: 'EUR' }
];
accounts.sort((a, b) => {
});