-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise8.js
36 lines (29 loc) · 910 Bytes
/
exercise8.js
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
var _ = require("lodash");
var array = [ { name: "mike", income: 2563 },
{ name: "kim", income: 1587 },
{ name: "liz", income: 3541 },
{ name: "tom", income: 2475 },
{ name: "bello", income: 987 },
{ name: "frank", income: 2975 } ]
var total = function(){
return _.reduce(array, (sum, value) => sum + value.income, 0)
}
var worker = function(){
let size = _.size(array)
let averageIncome = total() / size
let underperform = []
let overperform = []
_.filter(array, function(item){
if(item.income < averageIncome){
underperform.push(item)
}else if(item.income > averageIncome){
overperform.push(item)
}
})
return {
"average": averageIncome,
"underperform": _.sortBy(underperform, function(x) {return x.income;}),
"overperform": _.sortBy(overperform, function(y){return y.income;})
}
};
module.exports = worker;