Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Operations functions have to return a functions

    that recieves a number, provides math operation and returns math result

    let plus      = (r) => (l) => l + r
    let minus     = (r) => (l) => l - r
    let times     = (r) => (l) => l * r
    let dividedBy = (r) => (l) => l / r
    

    So our num function should recive the operation func or none (undefined)
    if f is undefined we have to return a number, or pass the number into function f and get result

    //simple realization
    (f) => { 
      if(f) {
        return f(num)
      } 
      return num
    }
    //now we can hide f check in args definition
    (f = function(val){ return val }) => f(num)
    //and simplify it with arrow function
    (f = val => val) => f(num)
    

    ANd we automaticaly declare all nums functions by using this[math] = *function*

    'zero one two three four five six seven eight nine'.split(' ').forEach(...)
    

    mth - it's element of array and the name of function ('one', 'two', 'three' etc.)

    num - it's a index of array and the numeric value (0, 1, 2, 3 etc.)

    (mth, num) => this[mth] = (f = val => val) => f(num) 
    
  • Custom User Avatar

    Operations functions have to return a functions

    that recieves a number, provides math operation and returns math result

    let plus      = (r) => (l) => l + r
    let minus     = (r) => (l) => l - r
    let times     = (r) => (l) => l * r
    let dividedBy = (r) => (l) => l / r
    

    So our num function should recive the operation func or none (undefined)
    if f is undefined we have to return a number, or pass the number into function f and get result

    //simple realization
    (f) => { 
      if(f) {
        return f(num)
      } 
      return num
    }
    //now we can hide f check in args definition
    (f = function(val){ return val }) => f(num)
    //and simplify it with arrow function
    (f = val => val) => f(num)
    

    ANd we automaticaly declare all nums functions by using this[math] = *function*

    'zero one two three four five six seven eight nine'.split(' ').forEach(...)
    

    mth - it's element of array and the name of function ('one', 'two', 'three' etc.)

    num - it's a index of array and the numeric value (0, 1, 2, 3 etc.)

    (mth, num) => this[mth] = (f = val => val) => f(num)