1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_6/Comprehensions/nested-for-if.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,20 @@ 1.4 +// For and if clauses can nest without limit in comprehensions. This is 1.5 +// unlike JS 1.8 comprehensions, which can only have one trailing "if" 1.6 +// clause. 1.7 + 1.8 +function* range(start, end) { 1.9 + for (var n = start; n < end; n++) 1.10 + yield n; 1.11 +} 1.12 + 1.13 +function primesBetween6And25() { 1.14 + return [for (n of range(6, 25)) if (n % 2) if (n % 3) if (n % 5) n]; 1.15 +} 1.16 +assertDeepEq(primesBetween6And25(), [7,11,13,17,19,23]); 1.17 + 1.18 +function countUpToEvens(limit) { 1.19 + return [for (n of range(0, limit)) if (!(n % 2)) for (m of range(0, n)) m] 1.20 +} 1.21 +assertDeepEq(countUpToEvens(7), [0,1,0,1,2,3,0,1,2,3,4,5]); 1.22 + 1.23 +reportCompare(null, null, "test");