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.
nice
Simple and readable
Using
_
as a placeholder for "this identifier exists but is not being used" has precedent in other languages and in practice, which makes it preferable IMO to most other choices. It's less about being shorter and more about signalling to the reader that this variable is deliberately being ignored.Of course, JS as a language makes no actual accomodation for this. We can already completely omit unused identifiers in destructuring e.g.
let [,,baz] = ['foo','bar','baz']
, and being able to do that in function declarations as well would make sense, e.g.someArray.filter((,index) => <whatever>)
. Shame we can't.I wouldn't consider using an underscore as a parameter name any simpler than any other naming convention, but it is certainly shorter. If parameter naming length is an important design consideration for you, perhaps using the
arguments
object instead of named parameters would be a better solution.but wouldn't it have been simpler to put
_
to ignore the first parameter?This comment is hidden because it contains spoiler information about the solution
What is the point of having the elem? Why can't you just leave index in the parenthesis ?
I'm finally getting the hang of this stuff. This is what I did.
thanks for your advice, i will take it into consideration next time
Splicing the parameter will modify the original array which might cause code to break elsewhere.
Best approach here to avoid that is to clone items. If it is a shallow array like so:
const itemsClone = [...items];
really clever :O
The statement doesn't say what to do for this case.
it does not work for empty elements. Try [, , 3, 4]
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Loading more items...