I am trying to get the value of the client using the client's name and for some reason I get back the full client object:
function createBank(clients) {
return {
clients: clients,
safeBoxValue: function() {
return this.clients.reduce(function(sum, client) {
return sum + client.value;
}, 0);
},
getclientValue: function(clientName) {
return this.clients.find(function(client) {
if (client.name === clientName) {
return client.value;
}
});
}
}
}
var clients = [
{name: "John", value: 349},
{name: "Jane", value: 9241},
{name: "Jill", value: 12734},
]
var bank = createBank(clients);
bank.safeBoxValue(); // 22324
bank.getclientValue('Jill'); // {"name":"Jill","value":12734}
Anybody knows why? Thanks!