mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-14 09:17:55 -05:00
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.
This commit is contained in:
@@ -3,7 +3,7 @@ eat food for food in ['toast', 'cheese', 'wine']
|
||||
|
||||
# Fine dining
|
||||
courses = ['salad', 'entree', 'dessert']
|
||||
menu course + 1, dish for dish, course in courses
|
||||
menu index + 1, dish for dish, index in courses
|
||||
|
||||
# Health conscious meal
|
||||
foods = ['broccoli', 'spinach', 'chocolate']
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var course, courses, dish, food, foods, _i, _j, _len, _len2, _len3, _ref;
|
||||
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++) {
|
||||
@@ -8,9 +8,9 @@ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
|
||||
courses = ['salad', 'entree', 'dessert'];
|
||||
|
||||
for (course = 0, _len2 = courses.length; course < _len2; course++) {
|
||||
dish = courses[course];
|
||||
menu(course + 1, dish);
|
||||
for (index = 0, _len2 = courses.length; index < _len2; index++) {
|
||||
dish = courses[index];
|
||||
menu(index + 1, dish);
|
||||
}
|
||||
|
||||
foods = ['broccoli', 'spinach', 'chocolate'];
|
||||
|
||||
Reference in New Issue
Block a user