jashkenas/coffee-script — Issue #1884: Shouldn't prefix embeded js with return
Author: gravof
Created: 2011-11-21 07:37:10+00:00
State: open

```coffeescript
->
`for(var i = arr.length -1; i >= 0 ; --i) {}`
```

gets compiled to

```javascript
(function() {
return for(var i = arr.length -1; i >= 0 ; --i) {};
});
```

Since there is no elegant way to iterate an array in reversed order in CS, I have to resort to embeded js, but this particular use case apparently doesn't work.

I know I can use `for item in arr.reverse()`, but `arr.reverse()` has the side effect of mutating the array, so I have to clone the array before reverse it, which kinda sucks.

I noticed backward iteration is only possible for syntax like `for i in [10..1] by -1`, which is rather counter-intuitive btw. `by -1` looks like making the iteration backwards already, and since the range is in revered order, you would expect this comprehension to actually use forward iteration, for double negative is positive.

Maybe something like `for item in reversed arr by step`?

Oops, I seem to have digressed.