make array comprehensions use for-of unless using an array literal - fixes #98

This commit is contained in:
Sebastian McKenzie
2014-11-03 21:15:49 +11:00
parent 816c1d304b
commit 6e5917e537
11 changed files with 40 additions and 37 deletions

View File

@@ -0,0 +1 @@
var arr = [for (i of [1, 2, 3]) if (i > 1) i * i];

View File

@@ -0,0 +1,7 @@
"use strict";
var arr = [1, 2, 3].filter(function (i) {
return i > 1;
}).map(function (i) {
return i * i;
});

View File

@@ -2,16 +2,21 @@
var seattlers = (function () {
var _arr = [];
countries.forEach(function (customers) {
customers.forEach(function (c) {
for (var _iterator = countries[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
var customers = _step.value;
for (var _iterator2 = customers[Symbol.iterator](), _step2; !(_step2 = _iterator2.next()).done;) {
var c = _step2.value;
if (c.city == "Seattle") {
_arr.push({
name: c.name,
age: c.age
});
}
});
});
}
}
return _arr;
})();
})();

View File

@@ -2,11 +2,16 @@
var arr = (function () {
var _arr = [];
"abcdefgh".split("").forEach(function (x) {
"12345678".split("").forEach(function (y) {
for (var _iterator = "abcdefgh".split("")[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
var x = _step.value;
for (var _iterator2 = "12345678".split("")[Symbol.iterator](), _step2; !(_step2 = _iterator2.next()).done;) {
var y = _step2.value;
_arr.push(x + y);
});
});
}
}
return _arr;
})();
})();

View File

@@ -1 +0,0 @@
var seattlers = [for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }];

View File

@@ -1,10 +0,0 @@
"use strict";
var seattlers = customers.filter(function (c) {
return c.city == "Seattle";
}).map(function (c) {
return {
name: c.name,
age: c.age
};
});