Advertisement
makispaiktis

Codecademy - 23th Course (Example of Higher-Order Functions)

Dec 18th, 2019 (edited)
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const checkThatTwoPlusTwoEqualsFourAMillionTimes = () => {
  2.   for(let i = 1; i <= 1000000; i++) {
  3.     if ( (2 + 2) != 4) {
  4.       console.log('Something has gone very wrong :( ');
  5.     }
  6.   }
  7. };
  8.  
  9. const addTwo = num => num + 2;
  10.  
  11. const timeFuncRuntime = funcParameter => {
  12.   let t1 = Date.now();
  13.   funcParameter();
  14.   let t2 = Date.now();
  15.   return t2 - t1;
  16. };
  17.  
  18. // Write your code below
  19. let time2p2 = timeFuncRuntime(checkThatTwoPlusTwoEqualsFourAMillionTimes);
  20.  
  21. function checkConsistentOutput(funcParam, value){
  22.   let value1 = funcParam(value);
  23.   let value2 = funcParam(value);
  24.   if(value1 === value2){
  25.    return funcParam(value);
  26.   }
  27.   else{
  28.     return 'This function returned inconsistent results';
  29.   }
  30. }
  31.  
  32. checkConsistentOutput(addTwo, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement