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.
Although it is said there will be no empty array in instruction, for general use cases If the array is empty, this will panic compiler.
It's dereferencing the result of .unwrap()
Noooo! I can't believe
Compiler told me to dereference 'arr' by adding the *. Don't understand why yet...
That makes sense. Thank you for the kata and clarification!
Kata author here: indeed, "real" spy libraries might be more useful with a method like you propose, and that could very well have made for a better kata (albeit slightly more challenging). The requirement that this kata record all arguments in all positions and treat them as comparable was meant to be a minimalistic demonstration of the following concepts:
spyOn
returns new, separate spy functionsIf I were rewriting this kata today, I might have tried to make the library more "realistic" in its API and capabilities. That being said, I suspect that anyone who can solve this kata as intended would also be able to solve for a method like you describe.
Could someone please explain to me why we have to return true if a function was called with a specific argument instead of set of arguments?
I just don't see how that can be a desirable outcome.
Say, we call adderSpy(1, 2, 3)
and adderSpy.wasCalledWith(2) must return true.
Wouldn't it be much more meaningful only for adderSpy.wasCalledWith(1, 2, 3) to return true in this case?
Amazing explanation for probably the most effective solution!
Sorting given array seems like a wasted effort in this case, especially when you consider that it's not even properly sorted. That would still get the job done, but it's an expensive solution.