Anonymous user
Closures/Value capture: Difference between revisions
m
used a different font for (italic) lowercase "i".
No edit summary |
m (used a different font for (italic) lowercase "i".) |
||
Line 2:
;Task:
Create a list of ten functions, in the simplest manner possible (anonymous functions are encouraged), such that the function at index <big> ''<b> i </b>'' </big> (you may choose to start <big> ''<b> i </b>'' </big> from either <big> '''0''' </big> or <big> '''1'''), </big> when run, should return the square of the index, that is, <big> ''<b> i </b>'' <sup>2</sup>.</big>
Display the result of running any but the last function, to demonstrate that the function indeed remembers its value.
|