-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1672-richest-customer-wealth.js
More file actions
65 lines (44 loc) · 1.46 KB
/
1672-richest-customer-wealth.js
File metadata and controls
65 lines (44 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//Dec-18-2020
// You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the ith customer has in the jth bank. Return the wealth that the richest customer has.
// A customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth.
//For Of loop
var maximumWealth = function(accounts) {
let max = 0;
for(customer of accounts){
let bankAccount = 0
for(bank of customer){
bankAccount += bank
}
//console.log("bankAccount", bankAccount)
if(max < bankAccount) max = bankAccount
}
return max
};
/// MAP
var maximumWealth = function(accounts) {
let max = 0
const customer = accounts.map( x => {
bankAccount = 0
x.map(y => bankAccount+=y )
if(max < bankAccount) max = bankAccount
}
)
return max
}
//Reducer 1
var maximumWealth = function(accounts) {
let max = 0
for(customer of accounts){
if(customer.reduce((sum, max) => sum + max) > max) max = customer.reduce((sum, max) => sum + max)
}
return max
};
// reducer 2
var maximumWealth = function(accounts){
let max = 0
for(customer of accounts) {
let sum = customer.reduce((sum, curr) => sum + curr)
if (sum > max) max = sum
}
return max
};