Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. /**
  2. * Example 2:
  3. * Calculating average salary gain per year. callbackFn is our core
  4. * function to dectate gow to handle the data.
  5. */
  6. function callbackFn([tSal, tExp], data) {
  7. tSal = tSal + data.salary;
  8. tExp = tExp + data.expInYears;
  9. return [tSal, tExp];
  10. }
  11.  
  12. // using destructuring to extract the final result from myReducer
  13. const [ tSalary, tExperince ] = myReducer(developers, callbackFn, [0,0]);
  14. const aveSalPerYear = Math.floor(tSalary/tExperince);
  15.  
  16. console.log(aveSalPerYear); // 25833
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement