As others have pointed out, the semantics are pretty hard to deal with. But, it's the style that I think is the really bad part of this snippet. Why would you create an array of empty elements to iterate over just to grab the index? In CoffeeScript, however, the language guides you to this solution:
It's not like the syntax is that bad. But, iterators are simpler than indexing a collection. Iterators work with data structures like linked lists where you don't really have an index. And, they work when the collection changes while you're iterating it.
I have, except that it's not really my solution. I was just cleaning up the example to make it more readable, as that seemed to be one of the complaints of the OP.
Comments
As others have pointed out, the semantics are pretty hard to deal with. But, it's the style that I think is the really bad part of this snippet. Why would you create an array of empty elements to iterate over just to grab the index? In CoffeeScript, however, the language guides you to this solution:
where you're operating on the elements of your array and you don't care about their index.Because it's the shortest way to do it in that language.
I think something like:
or: might even be better. Do you know of a language with that syntax?If you want an index, use an index:
It's not like the syntax is that bad. But, iterators are simpler than indexing a collection. Iterators work with data structures like linked lists where you don't really have an index. And, they work when the collection changes while you're iterating it.But you can't also output an array without additional lines of code.
You still haven't realized that _your_ solution won't output anything without additional lines of code, have you?
I have, except that it's not really my solution. I was just cleaning up the example to make it more readable, as that seemed to be one of the complaints of the OP.