2009-12-24 00:42:18 +00:00
|
|
|
(function(){
|
2010-02-21 16:45:03 +00:00
|
|
|
var _a, _b, _c, cubed_list, list, math, num, number, opposite_day, race, square;
|
2009-12-24 00:42:18 +00:00
|
|
|
// Assignment:
|
2009-12-26 07:17:34 +00:00
|
|
|
number = 42;
|
|
|
|
opposite_day = true;
|
2009-12-24 00:42:18 +00:00
|
|
|
// Conditions:
|
|
|
|
if (opposite_day) {
|
|
|
|
number = -42;
|
|
|
|
}
|
|
|
|
// Functions:
|
2009-12-31 04:43:55 +00:00
|
|
|
square = function square(x) {
|
2009-12-24 00:42:18 +00:00
|
|
|
return x * x;
|
|
|
|
};
|
|
|
|
// Arrays:
|
2009-12-26 07:17:34 +00:00
|
|
|
list = [1, 2, 3, 4, 5];
|
2009-12-24 00:42:18 +00:00
|
|
|
// Objects:
|
2009-12-26 07:17:34 +00:00
|
|
|
math = {
|
2009-12-24 00:42:18 +00:00
|
|
|
root: Math.sqrt,
|
|
|
|
square: square,
|
2009-12-31 04:43:55 +00:00
|
|
|
cube: function cube(x) {
|
2009-12-24 00:42:18 +00:00
|
|
|
return x * square(x);
|
|
|
|
}
|
|
|
|
};
|
2010-01-05 05:34:18 +00:00
|
|
|
// Splats:
|
|
|
|
race = function race(winner) {
|
|
|
|
var runners;
|
|
|
|
runners = Array.prototype.slice.call(arguments, 1);
|
|
|
|
return print(winner, runners);
|
|
|
|
};
|
|
|
|
// Existence:
|
|
|
|
if ((typeof elvis !== "undefined" && elvis !== null)) {
|
|
|
|
alert("I knew it!");
|
|
|
|
}
|
2009-12-24 00:42:18 +00:00
|
|
|
// Array comprehensions:
|
2010-01-05 00:15:24 +00:00
|
|
|
cubed_list = (function() {
|
2010-02-21 16:45:03 +00:00
|
|
|
_a = []; _b = list;
|
|
|
|
for (_c = 0; _c < _b.length; _c++) {
|
|
|
|
num = _b[_c];
|
|
|
|
_a.push(math.cube(num));
|
2009-12-31 21:50:46 +00:00
|
|
|
}
|
2010-02-21 16:45:03 +00:00
|
|
|
return _a;
|
2010-01-25 05:14:00 +00:00
|
|
|
}).call(this);
|
2009-12-24 00:42:18 +00:00
|
|
|
})();
|