Advertisement
vit134

Калькулятор на функциях (Яндекс)

Nov 9th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     написать калькулятор вида five(pluc(one())) // 6
  3. */
  4.  
  5. function five(fn) {
  6.     if (fn) return fn(5);
  7.     return 5;
  8. }
  9.  
  10. function one(fn) {
  11.     if (fn) return fn(1);
  12.     return 1;
  13. }
  14.  
  15. function two(fn) {
  16.     if (fn) return fn(2);
  17.     return 2;
  18. }
  19.  
  20. function seven(fn) {
  21.     if (fn) return fn(7);
  22.     return 7;
  23. }
  24.  
  25. function add(val) {
  26.     return function(v) {
  27.         return v + val;
  28.     }
  29. }
  30.  
  31. function subtract(val) {
  32.     return function(v) {
  33.         return v - val;
  34.     }
  35. }
  36.  
  37. console.log('---calculator---')
  38. console.log(five(add(one())));
  39. console.log(seven(subtract(two())))
  40. console.log('----------------')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement