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.
answered above
Thats awesome, knew about first but second was just gamechanger. Thank you
Depends. With simple exercises like this one, compact solutions are used in production. However, with more complex algorithms, code golfing is more of a past time. Self documenting and legible code is more desireable for professinal production code, as it's easier to read and maintain.
@Tobleron44 What language are you on? That sounds like an error in the description, since the correct output should be 1, 3, 5, 7, 9, 2, 6, 10, 8, 4.
Also, when you start your second run through, you forgot to switch from yes to no. You end on 10 (no), so when you go back to 2, it should be a yes.
But that would mean:
y n y n y n y n y n
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
1, 3, 5, 7, 9
then we have
N Y N Y N
2, 4, 6, 8, 10
1, 3, 5, 7, 9, 4, 8
...
And in the description it says
1, 3, 5, 7, 9, 2, 4, 6, 8, 4
what am i missing?
cool.
As I understand it, you need to write a function which takes an array, and returns another array. To populate the output array, go through the input, and select every other item. Once you reach the end, loop through the input array again with the same pattern, ignoring the items which were "selected" previously. However, when you restart the array, the decision to either include or exclude an item doesn't reset. So if you selected the last item, ignore the first item when you restart the array.
For example, take the array [1, 2, 3, 4, 5]
First, go through every other element, like so:
After "removing" these elements, we are left with
[2, 4]
, so we repeate the same pattern. However, because our last runthrough ended with a "Yes", this new runthrough starts with a "No":Now, since only
[2]
is left in our input form, we add it to the end of the output, returning[1, 3, 5, 4, 2]
.Hopefully that makes a bit more sense.
This comment is hidden because it contains spoiler information about the solution
Are the most concise functions commmonly used in product code? Or is it generally more readable?
this makes a lot of sense... will definately take note of this.
You're not doing anything about the descending order.
This comment is hidden because it contains spoiler information about the solution
This is a fantastic solution. Very well done!
False
and0
are different.Also, note that if you don't tell what's the input, what's the expected output and what's the result your code returned, nobody can help you.
Loading more items...