List comprehensions: Difference between revisions

Content added Content deleted
Line 798: Line 798:




JavaScript 1.6 onwards (while we wait for array comprehension syntax in JavaScript 1.7) we can emulate the parts of a list comprehension expression by applying '''Array.prototype.filter''' to a functionally defined set, returning a list of matches.
In JavaScript 1.6 onwards (while we wait for array comprehension syntax in JavaScript 1.7) we can emulate the parts of a list comprehension expression by applying '''Array.prototype.filter''' to a functionally defined set, returning a list of matches.


Following the pattern of the [[#Mathematica|Mathematica]] example, and using functional set definitions, rather than for loops:
Following the pattern of the [[#Mathematica|Mathematica]] example, and using functional set definitions, rather than for loops: