1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/documentation/js/array_comprehensions.js
Jo Liss 57e109ff11 Use "index" for index variable in for loop
This confused me every time I Ctrl+F'ed the home page for "index" and only got
this cryptic statement:

"Comprehensions replace (and compile into) for loops, with optional guard clauses
and the value of the current array index."

Now I can see how the index is used in the code.
2011-11-23 16:25:21 +01:00

21 lines
522 B
JavaScript

var courses, dish, food, foods, index, _i, _j, _len, _len2, _len3, _ref;
_ref = ['toast', 'cheese', 'wine'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
food = _ref[_i];
eat(food);
}
courses = ['salad', 'entree', 'dessert'];
for (index = 0, _len2 = courses.length; index < _len2; index++) {
dish = courses[index];
menu(index + 1, dish);
}
foods = ['broccoli', 'spinach', 'chocolate'];
for (_j = 0, _len3 = foods.length; _j < _len3; _j++) {
food = foods[_j];
if (food !== 'chocolate') eat(food);
}