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.
conversion to string and lookup in it can't be efficient
looks like String(bool) comparison against "true"
Yes, it's elegant. But at the same time, it needs to iterate all the range from zero to n. I think this way wastes a lot of time when n is a big number.
Really nice! Very elegant.
This comment is hidden because it contains spoiler information about the solution
Whew. How does this work?
This comment is hidden because it contains spoiler information about the solution
Please can anyone explain me the logic here?
thanks for the reply. I tend to write code as clean as possible so that it is understandable. I haven't had a case where I needed to optimize my code, but this should help when that day comes.
In general, less code is always better. Less to maintain, less to go wrong. Also, the compiler does some optimisation when it sees these patterns to run them in the most efficient way.
There are some rare cases where you will need to write optimised code yourself because the compiler doesn't know how to optimise them. One example I can think of is nested loops.
clever. I'm curious in general, is code more efficient during runtime when it is coded like this as opposed to a more verbose method?
either way, nice solution
You are welcome :)
thanks again for your time, i think i got it, really appreciate.
Well, no.
$N
values are values inside the closure. To accessstart
orend
just usestart
andend
inside the closure.If there are a single parameter inside the closure, only
$0
will be available. As an example -.filter(...)
could be written as:With this you can't access parameters with
$0
, but can with it's name -item
.For example
.sort(...)
method uses 2 parameters inside, so this:Is the same as this:
I guess it will be easier to understand if you read about
Shorthand Argument Names
at: Swift Bookthanks for answering, just to be sure, the filter method itself is what $0 represents here, right? and paramater start would be $1, and parameter end will be $2?
Loading more items...