Tengo una matriz de cuentas de objetos:
accounts[{type: "debit", currency: "EUR"}{type, currency}{type, currency}...]Y necesito ordenar la matriz de cuentas en el siguiente orden: débito -> crédito -> externo -> ahorro -> préstamo. Si hay varias cuentas con un tipo, ordene según la moneda: RUB -> USD -> EUR -> GBP. Tengo:
accounts.sort(function(a, b) { let aStatus = 1; let bStatus = 1; if (a.type === "credit") { aStatus = 5; } if (a.type === "external") { aStatus = 9; } if (a.type === "saving") { aStatus = 13; } if (a.type === "loan") { aStatus = 17; } if (b.type === "credit") { bStatus = 5; } if (b.type === "external") { aStatus = 9; } if (b.type === "saving") { bStatus = 13; } if (b.type === "loan") { bStatus = 17; } if (a.currency === "USD") { aStatus += 1; } if (a.currency === "EUR") { aStatus += 2; } if (a.currency === "GBP") { aStatus += 3; } if (b.currency === "USD") { bStatus += 1; } if (b.currency === "EUR") { bStatus += 2; } if (b.currency === "GBP") { bStatus += 3; } return aStatus - bStatus; })Primer problema: no funciona. Segundo: no parece racionalidad y enorme. Ayúdame por favor a hacer un mejor código.