通过 es6,该练习包括显示对象,其中键是银行名称和处置值与客户的文本编号。
具有以下矩阵
const clients = [
{ id: 1, taxNumber: '86620855', name: 'HECTOR ACUÑA BOLAÑOS'},
{ id: 2, taxNumber: '7317855K', name: 'JESUS RODRIGUEZ ALVAREZ'},
{ id: 3, taxNumber: '73826497', name: 'ANDRES NADAL MOLINA'},
{ id: 4, taxNumber: '88587715', name: 'SALVADOR ARNEDO MANRIQUEZ'},
{ id: 5, taxNumber: '94020190', name: 'VICTOR MANUEL ROJAS LUCAS'},
{ id: 6, taxNumber: '99804238', name: 'MOHAMED FERRE SAMPER' }
];
const accounts = [
{ clientId: 6, bankId: 1, balance: 15000 },
{ clientId: 1, bankId: 3, balance: 18000 },
{ clientId: 5, bankId: 3, balance: 135000 },
{ clientId: 2, bankId: 2, balance: 5600 },
{ clientId: 3, bankId: 1, balance: 23000 },
{ clientId: 5, bankId: 2, balance: 15000 },
{ clientId: 3, bankId: 3, balance: 45900 },
{ clientId: 2, bankId: 3, balance: 19000 },
{ clientId: 4, bankId: 3, balance: 51000 },
{ clientId: 5, bankId: 1, balance: 89000 },
{ clientId: 1, bankId: 2, balance: 1600 },
{ clientId: 5, bankId: 3, balance: 37500 },
{ clientId: 6, bankId: 1, balance: 19200 },
{ clientId: 2, bankId: 3, balance: 10000 },
{ clientId: 3, bankId: 2, balance: 5400 },
{ clientId: 3, bankId: 1, balance: 9000 },
{ clientId: 4, bankId: 3, balance: 13500 },
{ clientId: 2, bankId: 1, balance: 38200 },
{ clientId: 5, bankId: 2, balance: 17000 },
{ clientId: 1, bankId: 3, balance: 1000 },
{ clientId: 5, bankId: 2, balance: 600 },
{ clientId: 6, bankId: 1, balance: 16200 },
{ clientId: 2, bankId: 2, balance: 10000 }
]
const banks = [
{ id: 1, name: 'BankA' },
{ id: 2, name: 'BankB' },
{ id: 3, name: 'BankC' }
];
那么结果将是这样的:
0: {bank: 'BankA', clients: {'99804238', '94020190', '73826497'} } ,
1: {bank: 'BankB', clients: {'7317855K', '94020190', '86620855'} } ,
2: {bank: 'BankC', clients: {'73826497', '86620855', '88587715'} }
基本上,此结果包含包含客户值的银行名称,其中包含使用该银行的客户的所有文本编号。
最终结果将包含每家银行的客户总数,仅供参考。
function banksClientsTaxNumbers() {
var map = accounts.reduce(function(map, acc) {
var bankByid = acc.bankId
map[bankByid ] = {}
return map
}, {})
console.log(map)
var array = Object.keys(map).map(function(id) {
var bank = banks.find(function(bank) {
return bank.id == id;
})
var account = accounts.filter(function(account) {
return account.bankId == id;
})
console.log(account)
return {
banco: bank.name,
clients: account
}
});
console.log(array)
}
这段代码的结果是:
如您所见,每个银行包含的帐户都已列出,但我们仍然需要通过 textnumber 到达客户数组以显示它们,请帮助!
如果你实现了这个练习的逻辑,我提前谢谢你。问候!