2009-12-23 19:42:18 -05:00
|
|
|
(function(){
|
2010-01-10 15:52:23 -05:00
|
|
|
var __a, __b, __c, cubed_list, list, math, num, number, opposite_day, race, square;
|
2009-12-23 19:42:18 -05:00
|
|
|
// Assignment:
|
2009-12-26 02:17:34 -05:00
|
|
|
number = 42;
|
|
|
|
opposite_day = true;
|
2009-12-23 19:42:18 -05:00
|
|
|
// Conditions:
|
|
|
|
if (opposite_day) {
|
|
|
|
number = -42;
|
|
|
|
}
|
|
|
|
// Functions:
|
2009-12-30 23:43:55 -05:00
|
|
|
square = function square(x) {
|
2009-12-23 19:42:18 -05:00
|
|
|
return x * x;
|
|
|
|
};
|
|
|
|
// Arrays:
|
2009-12-26 02:17:34 -05:00
|
|
|
list = [1, 2, 3, 4, 5];
|
2009-12-23 19:42:18 -05:00
|
|
|
// Objects:
|
2009-12-26 02:17:34 -05:00
|
|
|
math = {
|
2009-12-23 19:42:18 -05:00
|
|
|
root: Math.sqrt,
|
|
|
|
square: square,
|
2009-12-30 23:43:55 -05:00
|
|
|
cube: function cube(x) {
|
2009-12-23 19:42:18 -05:00
|
|
|
return x * square(x);
|
|
|
|
}
|
|
|
|
};
|
2010-01-05 00:34:18 -05: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-23 19:42:18 -05:00
|
|
|
// Array comprehensions:
|
2010-01-04 19:15:24 -05:00
|
|
|
cubed_list = (function() {
|
2010-01-10 14:45:44 -05:00
|
|
|
__c = []; __a = list;
|
|
|
|
for (__b=0; __b<__a.length; __b++) {
|
|
|
|
num = __a[__b];
|
|
|
|
__c.push(math.cube(num));
|
2009-12-31 16:50:46 -05:00
|
|
|
}
|
2010-01-04 19:15:24 -05:00
|
|
|
return __c;
|
|
|
|
})();
|
2009-12-23 19:42:18 -05:00
|
|
|
})();
|