1

Create a function defineFirstArg that accepts a function and an argument. Also, the function being passed in will accept at least one argument. defineFirstArg will return a new function that invokes the passed-in function with the passed-in argument as the passed-in function's first argument. Additional arguments needed by the passed-in function will need to be passed into the returned function.

Below is my code:

const defineFirstArg = (inputFunc, arg) => {

  return function (argTwo) {
    return inputFunc(arg, argTwo)
  }
}

But it's failing the last test spec:

enter image description here

What am I doing wrong?

Nico Diz
  • 1,484
  • 1
  • 7
  • 20
PineNuts0
  • 4,740
  • 21
  • 67
  • 112

1 Answers1

2

the third test condition says arguments, not an argument so maybe you will need to try spread operator instead

    const defineFirstArg = (inputFunc, arg) => {

      return function (...addtionalArgs) {
        return inputFunc(arg, ...addtionalArgs)
      }
    }
  f2 = defineFirstArg(console.log,"x")
  f2("y","z",'f')
  //x y z f

to spread the parameters and execute the function passed on an unlimited number of parameters

M.Elkady
  • 1,093
  • 7
  • 13
  • 2
    where do I add ...arg? – PineNuts0 Jun 12 '19 at 19:38
  • 2
    i edited the answer to be more clear I hope it is the needed – M.Elkady Jun 12 '19 at 19:40
  • 1
    When I run your code above, it produces TypeError: Found non-callable @@iterator – PineNuts0 Jun 12 '19 at 19:42
  • 1
    after the last edit, i tested the code and it gives logical result to the behaviour described but ... operator is new es6 feature so it if the javascript version is older you can user `arguments` instead ..to make the second function accept unlimited number of arguments check this answer https://stackoverflow.com/questions/6396046/unlimited-arguments-in-a-javascript-function – M.Elkady Jun 12 '19 at 19:52