JS: for sample tests, values passed to Test.assertSimilar are reversed.
Here this refers to the function you call pipe on, so you call the original function with the arguments and pass the result to the piped function as an argument so addOne.pipe(square)(1) is actually square(addOne(1)) where this refers to addOne
This comment is hidden because it contains spoiler information about the solution
arrayLike --- An array-like or iterable object to convert to an array.
mapFn --- Optional Map function to call on every element of the array.
The Array.from() method creates a new, shallow-copied Array instance from an array-like or iterable object.
This was done.
nice and creative
Question: is the s = '' a default value for the parameter? Also, if so, should a default value also be set for n? Should default values always be set for parameters? Or is that a bad idea? Thanks for the insight.
Updated the description. Thanks !
Kata Description mentions that the array can be null or undefined but doesn't specify the expected behaviour from the user function (e.g. throw an error? Return undefined? Return the original array?). The Kata Description should make the expected behaviour of the user function crystal clear in the Description for all types of inputs that will appear in the test cases instead of leaving the user guessing and figuring it out after failing tests on submit.
I commented because I saw "never understood why .forEach() was invented" and I think not allocating space is enough difference to have forEach apart from map.
I said array of undefined because I assumed the usage in place of forEach. I also assumed that function given to forEach doesn't return anything (returns undefined) because there's no use. With these assumptions, the calculated value is undefined :)
Which is then eligible for garbage collection immediately. But for larger arrays, indeed, map will be slower. For smallish arrays, the difference will not be measurable I guess.
I wasn't so much joking as ignoring (OK, OK, forgetting :P ) the new array.
(It wouldn't be an array of undefineds either, wouldn't it? It would actually contain the calculated values.)