Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Example 2:
- * Calculating average salary gain per year. callbackFn is our core
- * function to dectate gow to handle the data.
- */
- function callbackFn([tSal, tExp], data) {
- tSal = tSal + data.salary;
- tExp = tExp + data.expInYears;
- return [tSal, tExp];
- }
- // using destructuring to extract the final result from myReducer
- const [ tSalary, tExperince ] = myReducer(developers, callbackFn, [0,0]);
- const aveSalPerYear = Math.floor(tSalary/tExperince);
- console.log(aveSalPerYear); // 25833
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement