Consider the following five snippets of
JavaScript code:
var m3 = is.map( function (n) { return n + 3; }, is.from(1));
console.log(is.take(m3,10));
|
var m3 = is.iterates( function (n) { return n * 3; }, 3);
console.log(is.take(m3,10));
|
var m3 = is.filter( function (n) { return n % 3 !== 0; }, is.from(1));
console.log(is.take(m3,10));
|
var m3 = function () {
var helper = function (n) {
return is.cons(n,helper(n + 3));
}
return helper(3);
};
console.log(is.take(m3(),10));
|
var m3 = function () {
var helper =
function (n) {
return is.cons(
is.hd(is.drop(is.from(n),2)),
function () {
return is.cons(
is.hd(is.drop(is.from(n + 3),2)),
function () {
return helper(n + 6);
});
});
};
return helper(1);
};
console.log(is.take(m3(),10));
|
Note that each one of these code snippets ends with a
print statement. Assuming that each code snippet is run by
itself, how many of them will output the following list?
[ 3, 6, 9, 12, 15, 18, 21, 24, 27, 30 ]
1
Make sure that each thunk is created/processed correctly
(e.g., each tail must be frozen).