rest parameters

how to do this

function myFun(a, b, ...manyMoreArgs) {
  console.log("a", a);
  console.log("b", b);
  console.log("manyMoreArgs", manyMoreArgs);
}

myFun("one", "two", "three", "four", "five", "six");

// a, "one"
// b, "two"
// manyMoreArgs, ["three", "four", "five", "six"] <-- an array

im trying to write grey ring functions but they have fixed # of parameters and i need variable #. do i have to just pass all args in 1 array or is there a better way

You can get the number of arguments in a grey ring by using this.

Which you can then use to determine the length of the input list. In fact, this is actually what the map block does.

thats not what im asking i want write a function the example one that has parameters a, b, manyMoreArgs, where i can call the function with 2+ arguments, like for ex. call (fn) with inps [1] [2] [3] [4] [5] [6], where inside the function it would set a =1, b =2 and manyMoreArgs = [3, 4, 5, 6],,, or call (fn) with inps [1] [2] [3] [4] would set a = 1, b=2, manyMoreArgs = [3,4].

Ah, I see what you're talking about now. The closest thing to that is a variadic input in a custom block (you can't do that in a ring).

Actually while I was testing this out, I found out that you can do this.

Unfortunately the variadic input takes in all the passed in inputs, so it's not exactly what you want.

... only if you have zero slots showing in the called block. Otherwise it does what you'd expect. Interesting.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.