Created
August 1, 2016 17:08
-
-
Save vsavkin/e1d74e821aa79cb952e33797778696d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function averageSalary(employees: Employee[], conditions: Predicate[]): number { | |
let total = 0; | |
let count = 0; | |
employees.forEach((e) => { | |
if(conditions.every(c => c(e))){ | |
total += e.salary; | |
count += 1; | |
} | |
}); | |
return (count === 0) ? 0 : total / count; | |
} | |
//... | |
expect(averageSalary(empls, [(e) => e.salary > 50, (e) => sales.works(e)])).toEqual(150); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment