0

Given an argument list and a two-arity function:

args = [5, 6]
f = ((y,z)->y*z)

How do I unroll args into function arguments? - E.g. in Python you can do: f(*args).

What I've tried (more JavaScript style I suppose):

Function.call.apply(f, args)
# When that failed, tried:
((y,z) -> y*z).call.apply(null, [5,6])
A T
  • 13,008
  • 21
  • 97
  • 158

1 Answers1

1

Use f(args...).

f = (x, y) -> x + y
list = [1, 2]
console.log(f(list...)) # -> 3

You can also mix and match this with regular arguments:

f = (a, b, c, d) -> a*b + c*d
list = [2, 3]
console.log(f(1, list..., 4)) # -> 1*2 + 3*4 == 14
user3374348
  • 4,101
  • 15
  • 29