-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmostProfitableDepartment.js
More file actions
37 lines (31 loc) · 980 Bytes
/
mostProfitableDepartment.js
File metadata and controls
37 lines (31 loc) · 980 Bytes
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
function mostProfitableDepartment(profDept){
//con.log(profDept);
var deptObj = {hardware:0,outdoor:0,carpentry:0, electronics:0};
var finalDept = {};
for(var prop in profDept){
var listDept =profDept[prop];
var dptName = listDept.deptName;
//var itemPrice = priceMap[itemName];
if(profDept[prop].department === 'hardware'){
deptObj.hardware+= profDept[prop].sales;
}
else if(profDept[prop].department === 'outdoor'){
deptObj.outdoor+= profDept[prop].sales;
}
else if(profDept[prop].department === 'carpentry'){
deptObj.carpentry+= profDept[prop].sales;
}
else if(profDept[prop].department === 'electronics'){
deptObj.electronics+= profDept[prop].sales;
}
}
var arraySort = [];
for(var salesDept in deptObj){
arraySort.push([salesDept,deptObj[salesDept]]);
}
arraySort.sort(function(a,b){
return b[1] - a[1];
})
console.log(arraySort[0][0]);
return arraySort[0][0];
}