Back when I had interviewed with Jet, during one of the several coding exercises I went through, there was one problem that stuck out.
The challenge was to write a function, add, that will satisfy any of the ways it is called below.
When I initially heard the question I was a bit perplexed as to how the solution would be implemented however having gotten more comfortable with ES6 syntax, as well as concepts such as partial application, over the last few months, revisiting this question becomes a lot more clear.
You can also set arguments:
Using this knowledge and knowing that the add function is looking for a base case, where the arguments object length is 4, it is best to implement this functionality first.
Now that takes care of the base case so if we were to run the test where 4 arguments are passed in we will have the sum, 10, returned.
In instances where the 4 arguments are not passed in, and the base case is not met, a partially applied function must be returned to add to the arguments that came before it, and continue to build the arguments object.
Now, with the comments removed: