JS:
for(i=this.current.arr.length;i<this.counterLength;i++){
dosomthing();
dosomethingelse();
}
COFFEE:
i = @current.arr.length
while i < @counterLength
dosomthing()
dosomethingelse()
i++
I know coffeescript has great loop syntax candy, but I can’t find a more elegant way of writing it than this. Is there a more coffeescripty way of doing this?
I know about:
for currentArr in current.arr
//and
for currentArr, 1 in current.arr
but i needs to start at @currentLength and not 0
The
[..]operator is what you are looking for:No need to predefine
startandend, I just used it to make the code a bit clearer. Note that ifstartis greater thenend, then it will go backwards.Actually you need
[...]operator, because you used<instead of<=in the code. The[...]operator excludes the last element.