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.
This comment is hidden because it contains spoiler information about the solution
Darn it, i didn't need the else! nice code
(m <= 0 || n <= 0) no?
I mean, the answer literally is in the desciption.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Where is your else block???
Hi!
I've added some non numeric characters in random tests.
Thanks for the feedback!
the random testing is broken.
Testing for 16 9 4 20 18 12 8 1 7 14 3 13 10 2 17 5 19 6 15 21
It should work for random tests too: 1 should equal 11
UPD:
I was converting string to numbers.
So this is my issu
Nevertheless the description can be more clear for this case.
Or use in random test non numeric characters.
Use print in your code.
Try more and you can add print to your code to find input values for examples where you fail.
Had the same problem and then found that I have missed some cases.
First case don't filtering out non alphanumeric characters.
Second case where char in text string appearing more times then in original.
Great explanation, thank you!
Thanks. The key point for me was to understand than we use apply of bind. And "bind" has "apply" just like any other function.
The sneaky trick in this one is that we are
apply
ing thebind
function, not the inputfn
as you probably did.Let's break it down:
fn.bind( scope, arg1, arg2, ... )
bind
, when called on a functionf
, returns a new functiong
that callsf
with the provided scope, and optionally the provided arguments. It can be implemented like this:This allows us to call
g
at a later time, and guarantee that it will apply toscope
, as well as always have any arguments we provided ahead of time.fn.apply(scope, argArray)
apply
, when called on a functionf
, executes the functionf
as if it was called on the given scope, and passed in the provided args.So, these are equivilant
fn.bind.apply(fn, args)
This calls
apply
on thebind
function, because we have unknown values we want to bind to the originalfn
.If we knew the arguments, then these would be equivilant:
This is why passing in the extra
fn
in arguments is OK. In either case, what is returned is a new functiong
, that will callfn
with the arguments1, 2, 3
. By usingapply
, we can pass in the original arguments, without worrying about them.And that's basically it. We're using the built-in JavaScript function behavior to dynamically create a new function which will call the original function with the provided arguments.
It is very neat. But how does it work? In my solution I sliced initial arguments. But in this solution we just pass whole. What happens with arguments[0]?