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.
Oh, thank you. Now it makes sence for me
The first iteration will compare the first element and
undefined
.iterable[-1]
does not wrap around but will returnundefined
as there is no index -1.iterable.at(-1)
is required to wrap around and get the last element of an array.what if first and last elements of iterable will be the same?
I mean if we pass '323' in the first iteration, i === 0 so [i-1] will compare first (0) and last (-1) elements and filter will return ['2', '3'].
Correct me if I mistaken but I'll rather use [i+1] for compare
any use of filter could generally be made better by passing a third parameter to filter and using that for comparison, which would compare to the new copy rather than comparing to the parameter of function.
This is great! But it would not work correctly if the first element of the array
iterable
wasundefined
.Literally, since the variable is iterable, it is never a number.
.
This is not gonna work for a number
very elegant solution here. And quite readble, I think.
I don't have much deep knowledge about this topic, but... I feel like this code runs 2 diffirent loops? One of them for creating the array from the argument, one of them for the filter method? I am told that this is not a good practice, especially for longer arguments because it takes lots of resources from the computer. But... I always feel like this is more elegant solution.
Nice
somebody explain it to me pls
Knew there was a one line solution for this! Totally forogt about the ellipsis operator.
the largest annoyance with this kata was the input of both a string and a number array. the spread operator was quite a clever solution to solve that caveat.
you are always going to want to retain the first value in the iterable, so it does not matter that that comparison will always evaluate to true.
Loading more items...