momo3141

in-home

Jan 15th, 2023
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const createPerson = (name, age, gender) => {
  2.   return {
  3.     name,
  4.     age,
  5.     gender
  6.   };
  7. };
  8.  
  9. const add = (a, b) => {
  10.   console.log('exec.')
  11.   return a + b;
  12. }
  13. let countCalls = 0;
  14.  
  15. const decorateWithLogging = func => {
  16.  
  17.   return (a,b) => {
  18.     countCalls++
  19.     console.log(`Function called: ${countCalls}`);
  20.     return func(a,b)
  21.   }
  22.  
  23. };
  24.  
  25.  
  26. //const decoratedAdd = decorateWithLogging(add)(1,2);
  27. //const result = decoratedAdd(1, 2);
  28.  
  29. let counter = createCounter()
  30. let param1 = 0;
  31. let param2 = 0
  32.  
  33. let storeParameters  = (func) => {
  34.  
  35.   return (a,b) => {
  36.     if (param1 === a && param2 === b){
  37.       return result;
  38.     }
  39.     param1 = a;
  40.     param2 = b;
  41.     result = func(a,b)
  42.     return result
  43.   }
  44. }
  45.  
  46. console.log(storeParameters(add)(1,2))
  47. console.log(storeParameters(add)(1,2))
  48. console.log(storeParameters(add)(1,2))
  49. console.log(storeParameters(add)(2,2))
  50.  
  51.  
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment