Skip to content

Instantly share code, notes, and snippets.

@vsavkin
Created August 1, 2016 17:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vsavkin/e1d74e821aa79cb952e33797778696d6 to your computer and use it in GitHub Desktop.
Save vsavkin/e1d74e821aa79cb952e33797778696d6 to your computer and use it in GitHub Desktop.
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