Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Thanks!
But CodeWars submissions are not executed in your browser.
Also, the behavior is the same in every browser and even Node.js. You may only find problems when executing tests inside their consoles, as they might (Chrome, for instance, does) use
call
themselves.True. I had not dived into the inner working of console.log - however, have experienced a very similar problem without console.log.
As you point out, mrkish, the end result is the same (recursion).
My point is that working with Function.prototype.call/apply may give these problems - and I assume this could depend on the particular platform/browser you are running.
Actually, that's not how Javascript works.
Function.prototype.call
is not called for every function call.It just happens that CodeWars's
console.log
(orprint
) invokescall
onArray.prototype.slice
to do its thing. Of course, that means the end result is the same: callingconsole.log
incall
's body will end up in an infinite recursion. Calling other functions, in the other hand, is fine.Execution a function require a "call" to that function - as in f() where "f" is called using "()".
Though this may not be exactly as is works, you can imagine all JS function calls underneath are translated to the "generic" .call - which does the magic to set up "this" and "arguments" among other things.
So - calling a function like "f()" can be thought of as running "f.call(this)" (and app
Using this "thought technique" having console.log() in the code expands to:
Essentially calling call to expand the call....
Hope this clarify my line :)
Your function might be returning undefined. Are you returning anything?
I also tried this, until I realised that javascript's sort algorithm wasn't itself stable. So unless you want to implement your own sort algorithm in the answer, it's not really sensible to try it this way.
Excellent point, updated the description.