import 'local-file.coffee'
+import 'coffee-script'
-import _ from 'underscore'
-import * as underscore from 'underscore'
+import _ from 'underscore'
+import * as underscore from 'underscore'
-import { now } from 'underscore'
-import { now as currentTimestamp } from 'underscore'
-import { first, last } from 'underscore'
-import utilityBelt, { each } from 'underscore'
+import { now } from 'underscore'
+import { now as currentTimestamp } from 'underscore'
+import { first, last } from 'underscore'
+import utilityBelt, { each } from 'underscore'
-export default Math
-export square = (x) -> x * x
-export class Mathematics
+export default Math
+export square = (x) -> x * x
+export class Mathematics
least: (x, y) -> if x < y then x else y
-export { sqrt }
-export { sqrt as squareRoot }
-export { Mathematics as default, sqrt as squareRoot }
+export { sqrt }
+export { sqrt as squareRoot }
+export { Mathematics as default, sqrt as squareRoot }
-export * from 'underscore'
-export { max, min } from 'underscore'
+export * from 'underscore'
+export { max, min } from 'underscore'
import 'local-file.coffee';
import 'coffee-script';
@@ -2509,11 +2511,6 @@
assaf's Zombie.js,
a headless, full-stack, faux-browser testing library for Node.js.
-
- jashkenas' Underscore.coffee, a port
- of the Underscore.js
- library of helper functions.
-
stephank's Orona, a remake of
the Bolo tank game for modern browsers.
@@ -3890,6 +3887,16 @@
# Listen for keypresses and recompile.
$('#repl_source').keyup -> compileSource()
+ # Use tab key to insert tabs
+ $('#repl_source').keydown (e) ->
+ if e.keyCode is 9
+ e.preventDefault()
+ textbox = e.target
+ # Insert tab character at caret or in selection
+ textbox.value = textbox.value[0...textbox.selectionStart] + "\t" + textbox.value[textbox.selectionEnd...]
+ # Put caret in correct position
+ textbox.selectionEnd = ++textbox.selectionStart
+
# Eval the compiled js.
evalJS = ->
try
diff --git a/documentation/coffee/aliases.coffee b/documentation/examples/aliases.coffee
similarity index 100%
rename from documentation/coffee/aliases.coffee
rename to documentation/examples/aliases.coffee
diff --git a/documentation/coffee/array_comprehensions.coffee b/documentation/examples/array_comprehensions.coffee
similarity index 100%
rename from documentation/coffee/array_comprehensions.coffee
rename to documentation/examples/array_comprehensions.coffee
diff --git a/documentation/coffee/block_comment.coffee b/documentation/examples/block_comment.coffee
similarity index 100%
rename from documentation/coffee/block_comment.coffee
rename to documentation/examples/block_comment.coffee
diff --git a/documentation/coffee/cake_tasks.coffee b/documentation/examples/cake_tasks.coffee
similarity index 100%
rename from documentation/coffee/cake_tasks.coffee
rename to documentation/examples/cake_tasks.coffee
diff --git a/documentation/coffee/chaining.coffee b/documentation/examples/chaining.coffee
similarity index 100%
rename from documentation/coffee/chaining.coffee
rename to documentation/examples/chaining.coffee
diff --git a/documentation/coffee/classes.coffee b/documentation/examples/classes.coffee
similarity index 100%
rename from documentation/coffee/classes.coffee
rename to documentation/examples/classes.coffee
diff --git a/documentation/coffee/comparisons.coffee b/documentation/examples/comparisons.coffee
similarity index 100%
rename from documentation/coffee/comparisons.coffee
rename to documentation/examples/comparisons.coffee
diff --git a/documentation/coffee/conditionals.coffee b/documentation/examples/conditionals.coffee
similarity index 100%
rename from documentation/coffee/conditionals.coffee
rename to documentation/examples/conditionals.coffee
diff --git a/documentation/coffee/constructor_destructuring.coffee b/documentation/examples/constructor_destructuring.coffee
similarity index 100%
rename from documentation/coffee/constructor_destructuring.coffee
rename to documentation/examples/constructor_destructuring.coffee
diff --git a/documentation/coffee/default_args.coffee b/documentation/examples/default_args.coffee
similarity index 100%
rename from documentation/coffee/default_args.coffee
rename to documentation/examples/default_args.coffee
diff --git a/documentation/coffee/do.coffee b/documentation/examples/do.coffee
similarity index 100%
rename from documentation/coffee/do.coffee
rename to documentation/examples/do.coffee
diff --git a/documentation/coffee/embedded.coffee b/documentation/examples/embedded.coffee
similarity index 100%
rename from documentation/coffee/embedded.coffee
rename to documentation/examples/embedded.coffee
diff --git a/documentation/coffee/existence.coffee b/documentation/examples/existence.coffee
similarity index 100%
rename from documentation/coffee/existence.coffee
rename to documentation/examples/existence.coffee
diff --git a/documentation/coffee/expansion.coffee b/documentation/examples/expansion.coffee
similarity index 100%
rename from documentation/coffee/expansion.coffee
rename to documentation/examples/expansion.coffee
diff --git a/documentation/coffee/expressions.coffee b/documentation/examples/expressions.coffee
similarity index 100%
rename from documentation/coffee/expressions.coffee
rename to documentation/examples/expressions.coffee
diff --git a/documentation/coffee/expressions_assignment.coffee b/documentation/examples/expressions_assignment.coffee
similarity index 100%
rename from documentation/coffee/expressions_assignment.coffee
rename to documentation/examples/expressions_assignment.coffee
diff --git a/documentation/coffee/expressions_comprehension.coffee b/documentation/examples/expressions_comprehension.coffee
similarity index 100%
rename from documentation/coffee/expressions_comprehension.coffee
rename to documentation/examples/expressions_comprehension.coffee
diff --git a/documentation/coffee/expressions_try.coffee b/documentation/examples/expressions_try.coffee
similarity index 100%
rename from documentation/coffee/expressions_try.coffee
rename to documentation/examples/expressions_try.coffee
diff --git a/documentation/coffee/fat_arrow.coffee b/documentation/examples/fat_arrow.coffee
similarity index 100%
rename from documentation/coffee/fat_arrow.coffee
rename to documentation/examples/fat_arrow.coffee
diff --git a/documentation/coffee/functions.coffee b/documentation/examples/functions.coffee
similarity index 100%
rename from documentation/coffee/functions.coffee
rename to documentation/examples/functions.coffee
diff --git a/documentation/coffee/generators.coffee b/documentation/examples/generators.coffee
similarity index 100%
rename from documentation/coffee/generators.coffee
rename to documentation/examples/generators.coffee
diff --git a/documentation/coffee/heredocs.coffee b/documentation/examples/heredocs.coffee
similarity index 100%
rename from documentation/coffee/heredocs.coffee
rename to documentation/examples/heredocs.coffee
diff --git a/documentation/coffee/heregexes.coffee b/documentation/examples/heregexes.coffee
similarity index 100%
rename from documentation/coffee/heregexes.coffee
rename to documentation/examples/heregexes.coffee
diff --git a/documentation/coffee/interpolation.coffee b/documentation/examples/interpolation.coffee
similarity index 100%
rename from documentation/coffee/interpolation.coffee
rename to documentation/examples/interpolation.coffee
diff --git a/documentation/coffee/modules.coffee b/documentation/examples/modules.coffee
similarity index 100%
rename from documentation/coffee/modules.coffee
rename to documentation/examples/modules.coffee
diff --git a/documentation/coffee/modulo.coffee b/documentation/examples/modulo.coffee
similarity index 100%
rename from documentation/coffee/modulo.coffee
rename to documentation/examples/modulo.coffee
diff --git a/documentation/coffee/multiple_return_values.coffee b/documentation/examples/multiple_return_values.coffee
similarity index 100%
rename from documentation/coffee/multiple_return_values.coffee
rename to documentation/examples/multiple_return_values.coffee
diff --git a/documentation/coffee/object_comprehensions.coffee b/documentation/examples/object_comprehensions.coffee
similarity index 100%
rename from documentation/coffee/object_comprehensions.coffee
rename to documentation/examples/object_comprehensions.coffee
diff --git a/documentation/coffee/object_extraction.coffee b/documentation/examples/object_extraction.coffee
similarity index 100%
rename from documentation/coffee/object_extraction.coffee
rename to documentation/examples/object_extraction.coffee
diff --git a/documentation/coffee/objects_and_arrays.coffee b/documentation/examples/objects_and_arrays.coffee
similarity index 100%
rename from documentation/coffee/objects_and_arrays.coffee
rename to documentation/examples/objects_and_arrays.coffee
diff --git a/documentation/coffee/objects_reserved.coffee b/documentation/examples/objects_reserved.coffee
similarity index 100%
rename from documentation/coffee/objects_reserved.coffee
rename to documentation/examples/objects_reserved.coffee
diff --git a/documentation/coffee/overview.coffee b/documentation/examples/overview.coffee
similarity index 100%
rename from documentation/coffee/overview.coffee
rename to documentation/examples/overview.coffee
diff --git a/documentation/coffee/parallel_assignment.coffee b/documentation/examples/parallel_assignment.coffee
similarity index 100%
rename from documentation/coffee/parallel_assignment.coffee
rename to documentation/examples/parallel_assignment.coffee
diff --git a/documentation/coffee/patterns_and_splats.coffee b/documentation/examples/patterns_and_splats.coffee
similarity index 100%
rename from documentation/coffee/patterns_and_splats.coffee
rename to documentation/examples/patterns_and_splats.coffee
diff --git a/documentation/coffee/prototypes.coffee b/documentation/examples/prototypes.coffee
similarity index 100%
rename from documentation/coffee/prototypes.coffee
rename to documentation/examples/prototypes.coffee
diff --git a/documentation/coffee/range_comprehensions.coffee b/documentation/examples/range_comprehensions.coffee
similarity index 100%
rename from documentation/coffee/range_comprehensions.coffee
rename to documentation/examples/range_comprehensions.coffee
diff --git a/documentation/coffee/scope.coffee b/documentation/examples/scope.coffee
similarity index 100%
rename from documentation/coffee/scope.coffee
rename to documentation/examples/scope.coffee
diff --git a/documentation/coffee/slices.coffee b/documentation/examples/slices.coffee
similarity index 100%
rename from documentation/coffee/slices.coffee
rename to documentation/examples/slices.coffee
diff --git a/documentation/coffee/soaks.coffee b/documentation/examples/soaks.coffee
similarity index 100%
rename from documentation/coffee/soaks.coffee
rename to documentation/examples/soaks.coffee
diff --git a/documentation/coffee/splats.coffee b/documentation/examples/splats.coffee
similarity index 100%
rename from documentation/coffee/splats.coffee
rename to documentation/examples/splats.coffee
diff --git a/documentation/coffee/splices.coffee b/documentation/examples/splices.coffee
similarity index 100%
rename from documentation/coffee/splices.coffee
rename to documentation/examples/splices.coffee
diff --git a/documentation/coffee/strings.coffee b/documentation/examples/strings.coffee
similarity index 100%
rename from documentation/coffee/strings.coffee
rename to documentation/examples/strings.coffee
diff --git a/documentation/coffee/switch.coffee b/documentation/examples/switch.coffee
similarity index 100%
rename from documentation/coffee/switch.coffee
rename to documentation/examples/switch.coffee
diff --git a/documentation/coffee/switch_with_no_expression.coffee b/documentation/examples/switch_with_no_expression.coffee
similarity index 100%
rename from documentation/coffee/switch_with_no_expression.coffee
rename to documentation/examples/switch_with_no_expression.coffee
diff --git a/documentation/coffee/try.coffee b/documentation/examples/try.coffee
similarity index 100%
rename from documentation/coffee/try.coffee
rename to documentation/examples/try.coffee
diff --git a/documentation/coffee/while.coffee b/documentation/examples/while.coffee
similarity index 100%
rename from documentation/coffee/while.coffee
rename to documentation/examples/while.coffee
diff --git a/documentation/index.html.js b/documentation/index.html.js
index c2709d41cc..495201c269 100644
--- a/documentation/index.html.js
+++ b/documentation/index.html.js
@@ -33,6 +33,7 @@
Array Slicing and Splicing
Everything is an Expression
Operators and Aliases
+ Existential Operator
Classes, Inheritance, and Super
Destructuring Assignment
Bound and Generator Functions
@@ -716,6 +717,7 @@ Block
<%= codeFor('aliases') %>
+
It's a little difficult to check for the existence of a variable in
JavaScript. if (variable) ... comes close, but fails for zero,
@@ -1183,11 +1185,6 @@ Block
assaf's Zombie.js,
a headless, full-stack, faux-browser testing library for Node.js.
-
- jashkenas' Underscore.coffee, a port
- of the Underscore.js
- library of helper functions.
-
stephank's Orona, a remake of
the Bolo tank game for modern browsers.
@@ -2315,6 +2312,16 @@ six = ->
# Listen for keypresses and recompile.
$('#repl_source').keyup -> compileSource()
+ # Use tab key to insert tabs
+ $('#repl_source').keydown (e) ->
+ if e.keyCode is 9
+ e.preventDefault()
+ textbox = e.target
+ # Insert tab character at caret or in selection
+ textbox.value = textbox.value[0...textbox.selectionStart] + "\t" + textbox.value[textbox.selectionEnd...]
+ # Put caret in correct position
+ textbox.selectionEnd = ++textbox.selectionStart
+
# Eval the compiled js.
evalJS = ->
try
diff --git a/documentation/js/aliases.js b/documentation/js/aliases.js
deleted file mode 100644
index 13141ebce0..0000000000
--- a/documentation/js/aliases.js
+++ /dev/null
@@ -1,24 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var volume, winner;
-
-if (ignition === true) {
- launch();
-}
-
-if (band !== SpinalTap) {
- volume = 10;
-}
-
-if (answer !== false) {
- letTheWildRumpusBegin();
-}
-
-if (car.speed < limit) {
- accelerate();
-}
-
-if (pick === 47 || pick === 92 || pick === 13) {
- winner = true;
-}
-
-print(inspect("My name is " + this.name));
diff --git a/documentation/js/array_comprehensions.js b/documentation/js/array_comprehensions.js
deleted file mode 100644
index e585a802e8..0000000000
--- a/documentation/js/array_comprehensions.js
+++ /dev/null
@@ -1,24 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var courses, dish, food, foods, i, j, k, l, len, len1, len2, ref;
-
-ref = ['toast', 'cheese', 'wine'];
-for (j = 0, len = ref.length; j < len; j++) {
- food = ref[j];
- eat(food);
-}
-
-courses = ['greens', 'caviar', 'truffles', 'roast', 'cake'];
-
-for (i = k = 0, len1 = courses.length; k < len1; i = ++k) {
- dish = courses[i];
- menu(i + 1, dish);
-}
-
-foods = ['broccoli', 'spinach', 'chocolate'];
-
-for (l = 0, len2 = foods.length; l < len2; l++) {
- food = foods[l];
- if (food !== 'chocolate') {
- eat(food);
- }
-}
diff --git a/documentation/js/block_comment.js b/documentation/js/block_comment.js
deleted file mode 100644
index 3cebaabfbc..0000000000
--- a/documentation/js/block_comment.js
+++ /dev/null
@@ -1,7 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-
-/*
-SkinnyMochaHalfCaffScript Compiler v1.0
-Released under the MIT License
- */
-
diff --git a/documentation/js/cake_tasks.js b/documentation/js/cake_tasks.js
deleted file mode 100644
index e6c0c6f0d1..0000000000
--- a/documentation/js/cake_tasks.js
+++ /dev/null
@@ -1,14 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var fs;
-
-fs = require('fs');
-
-option('-o', '--output [DIR]', 'directory for compiled code');
-
-task('build:parser', 'rebuild the Jison parser', function(options) {
- var code, dir;
- require('jison');
- code = require('./lib/grammar').parser.generate();
- dir = options.output || 'lib';
- return fs.writeFile(dir + "/parser.js", code);
-});
diff --git a/documentation/js/chaining.js b/documentation/js/chaining.js
deleted file mode 100644
index 47e06e2ada..0000000000
--- a/documentation/js/chaining.js
+++ /dev/null
@@ -1,4 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-$('body').click(function(e) {
- return $('.box').fadeIn('fast').addClass('.active');
-}).css('background', 'white');
diff --git a/documentation/js/classes.js b/documentation/js/classes.js
deleted file mode 100644
index 77d7ece459..0000000000
--- a/documentation/js/classes.js
+++ /dev/null
@@ -1,57 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var Animal, Horse, Snake, sam, tom,
- extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
- hasProp = {}.hasOwnProperty;
-
-Animal = (function() {
- function Animal(name) {
- this.name = name;
- }
-
- Animal.prototype.move = function(meters) {
- return alert(this.name + (" moved " + meters + "m."));
- };
-
- return Animal;
-
-})();
-
-Snake = (function(superClass) {
- extend(Snake, superClass);
-
- function Snake() {
- return Snake.__super__.constructor.apply(this, arguments);
- }
-
- Snake.prototype.move = function() {
- alert("Slithering...");
- return Snake.__super__.move.call(this, 5);
- };
-
- return Snake;
-
-})(Animal);
-
-Horse = (function(superClass) {
- extend(Horse, superClass);
-
- function Horse() {
- return Horse.__super__.constructor.apply(this, arguments);
- }
-
- Horse.prototype.move = function() {
- alert("Galloping...");
- return Horse.__super__.move.call(this, 45);
- };
-
- return Horse;
-
-})(Animal);
-
-sam = new Snake("Sammy the Python");
-
-tom = new Horse("Tommy the Palomino");
-
-sam.move();
-
-tom.move();
diff --git a/documentation/js/comparisons.js b/documentation/js/comparisons.js
deleted file mode 100644
index 7c0d750102..0000000000
--- a/documentation/js/comparisons.js
+++ /dev/null
@@ -1,6 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var cholesterol, healthy;
-
-cholesterol = 127;
-
-healthy = (200 > cholesterol && cholesterol > 60);
diff --git a/documentation/js/conditionals.js b/documentation/js/conditionals.js
deleted file mode 100644
index 5bf2e239c9..0000000000
--- a/documentation/js/conditionals.js
+++ /dev/null
@@ -1,15 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var date, mood;
-
-if (singing) {
- mood = greatlyImproved;
-}
-
-if (happy && knowsIt) {
- clapsHands();
- chaChaCha();
-} else {
- showIt();
-}
-
-date = friday ? sue : jill;
diff --git a/documentation/js/constructor_destructuring.js b/documentation/js/constructor_destructuring.js
deleted file mode 100644
index e1a7bc2789..0000000000
--- a/documentation/js/constructor_destructuring.js
+++ /dev/null
@@ -1,17 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var Person, tim;
-
-Person = (function() {
- function Person(options) {
- var ref;
- this.name = options.name, this.age = options.age, this.height = (ref = options.height) != null ? ref : 'average';
- }
-
- return Person;
-
-})();
-
-tim = new Person({
- name: 'Tim',
- age: 4
-});
diff --git a/documentation/js/default_args.js b/documentation/js/default_args.js
deleted file mode 100644
index 8c5d57e636..0000000000
--- a/documentation/js/default_args.js
+++ /dev/null
@@ -1,9 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var fill;
-
-fill = function(container, liquid) {
- if (liquid == null) {
- liquid = "coffee";
- }
- return "Filling the " + container + " with " + liquid + "...";
-};
diff --git a/documentation/js/do.js b/documentation/js/do.js
deleted file mode 100644
index e15e02d01f..0000000000
--- a/documentation/js/do.js
+++ /dev/null
@@ -1,12 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var filename, fn, i, len;
-
-fn = function(filename) {
- return fs.readFile(filename, function(err, contents) {
- return compile(filename, contents.toString());
- });
-};
-for (i = 0, len = list.length; i < len; i++) {
- filename = list[i];
- fn(filename);
-}
diff --git a/documentation/js/embedded.js b/documentation/js/embedded.js
deleted file mode 100644
index 4a109757b8..0000000000
--- a/documentation/js/embedded.js
+++ /dev/null
@@ -1,6 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var hi;
-
-hi = function() {
- return [document.title, "Hello JavaScript"].join(": ");
-};
diff --git a/documentation/js/existence.js b/documentation/js/existence.js
deleted file mode 100644
index a262679b3b..0000000000
--- a/documentation/js/existence.js
+++ /dev/null
@@ -1,14 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var footprints, solipsism, speed;
-
-if ((typeof mind !== "undefined" && mind !== null) && (typeof world === "undefined" || world === null)) {
- solipsism = true;
-}
-
-speed = 0;
-
-if (speed == null) {
- speed = 15;
-}
-
-footprints = typeof yeti !== "undefined" && yeti !== null ? yeti : "bear";
diff --git a/documentation/js/expansion.js b/documentation/js/expansion.js
deleted file mode 100644
index 684fa39acf..0000000000
--- a/documentation/js/expansion.js
+++ /dev/null
@@ -1,6 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var first, last, ref, text;
-
-text = "Every literary critic believes he will outwit history and have the last word";
-
-ref = text.split(" "), first = ref[0], last = ref[ref.length - 1];
diff --git a/documentation/js/expressions.js b/documentation/js/expressions.js
deleted file mode 100644
index 262a2d122a..0000000000
--- a/documentation/js/expressions.js
+++ /dev/null
@@ -1,18 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var eldest, grade;
-
-grade = function(student) {
- if (student.excellentWork) {
- return "A+";
- } else if (student.okayStuff) {
- if (student.triedHard) {
- return "B";
- } else {
- return "B-";
- }
- } else {
- return "C";
- }
-};
-
-eldest = 24 > 21 ? "Liz" : "Ike";
diff --git a/documentation/js/expressions_assignment.js b/documentation/js/expressions_assignment.js
deleted file mode 100644
index bf656c0ec3..0000000000
--- a/documentation/js/expressions_assignment.js
+++ /dev/null
@@ -1,4 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var one, six, three, two;
-
-six = (one = 1) + (two = 2) + (three = 3);
diff --git a/documentation/js/expressions_comprehension.js b/documentation/js/expressions_comprehension.js
deleted file mode 100644
index b8f2618074..0000000000
--- a/documentation/js/expressions_comprehension.js
+++ /dev/null
@@ -1,11 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var globals, name;
-
-globals = ((function() {
- var results;
- results = [];
- for (name in window) {
- results.push(name);
- }
- return results;
-})()).slice(0, 10);
diff --git a/documentation/js/expressions_try.js b/documentation/js/expressions_try.js
deleted file mode 100644
index 2eab76a5e0..0000000000
--- a/documentation/js/expressions_try.js
+++ /dev/null
@@ -1,11 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var error;
-
-alert((function() {
- try {
- return nonexistent / void 0;
- } catch (error1) {
- error = error1;
- return "And the error is ... " + error;
- }
-})());
diff --git a/documentation/js/fat_arrow.js b/documentation/js/fat_arrow.js
deleted file mode 100644
index 1ddd3e16ac..0000000000
--- a/documentation/js/fat_arrow.js
+++ /dev/null
@@ -1,12 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var Account;
-
-Account = function(customer, cart) {
- this.customer = customer;
- this.cart = cart;
- return $('.shopping_cart').on('click', (function(_this) {
- return function(event) {
- return _this.customer.purchase(_this.cart);
- };
- })(this));
-};
diff --git a/documentation/js/functions.js b/documentation/js/functions.js
deleted file mode 100644
index fe52ad47bb..0000000000
--- a/documentation/js/functions.js
+++ /dev/null
@@ -1,10 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var cube, square;
-
-square = function(x) {
- return x * x;
-};
-
-cube = function(x) {
- return square(x) * x;
-};
diff --git a/documentation/js/generators.js b/documentation/js/generators.js
deleted file mode 100644
index 758c98b3d3..0000000000
--- a/documentation/js/generators.js
+++ /dev/null
@@ -1,13 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var perfectSquares;
-
-perfectSquares = function*() {
- var num;
- num = 0;
- while (true) {
- num += 1;
- yield num * num;
- }
-};
-
-window.ps || (window.ps = perfectSquares());
diff --git a/documentation/js/heredocs.js b/documentation/js/heredocs.js
deleted file mode 100644
index af5aca9ed5..0000000000
--- a/documentation/js/heredocs.js
+++ /dev/null
@@ -1,4 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var html;
-
-html = "\n cup of coffeescript\n";
diff --git a/documentation/js/heregexes.js b/documentation/js/heregexes.js
deleted file mode 100644
index 910ea0a444..0000000000
--- a/documentation/js/heregexes.js
+++ /dev/null
@@ -1,4 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var OPERATOR;
-
-OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
diff --git a/documentation/js/interpolation.js b/documentation/js/interpolation.js
deleted file mode 100644
index 0236d899f8..0000000000
--- a/documentation/js/interpolation.js
+++ /dev/null
@@ -1,8 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var author, quote, sentence;
-
-author = "Wittgenstein";
-
-quote = "A picture is a fact. -- " + author;
-
-sentence = (22 / 7) + " is a decent approximation of π";
diff --git a/documentation/js/modules.js b/documentation/js/modules.js
deleted file mode 100644
index 597790c603..0000000000
--- a/documentation/js/modules.js
+++ /dev/null
@@ -1,66 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-import 'local-file.coffee';
-
-import 'coffee-script';
-
-import _ from 'underscore';
-
-import * as underscore from 'underscore';
-
-import {
- now
-} from 'underscore';
-
-import {
- now as currentTimestamp
-} from 'underscore';
-
-import {
- first,
- last
-} from 'underscore';
-
-import utilityBelt, {
- each
-} from 'underscore';
-
-export default Math;
-
-export var square = function(x) {
- return x * x;
-};
-
-export var Mathematics = (function() {
- function Mathematics() {}
-
- Mathematics.prototype.least = function(x, y) {
- if (x < y) {
- return x;
- } else {
- return y;
- }
- };
-
- return Mathematics;
-
-})();
-
-export {
- sqrt
-};
-
-export {
- sqrt as squareRoot
-};
-
-export {
- Mathematics as default,
- sqrt as squareRoot
-};
-
-export * from 'underscore';
-
-export {
- max,
- min
-} from 'underscore';
diff --git a/documentation/js/modulo.js b/documentation/js/modulo.js
deleted file mode 100644
index 58b15e2fd9..0000000000
--- a/documentation/js/modulo.js
+++ /dev/null
@@ -1,8 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var modulo = function(a, b) { return (+a % (b = +b) + b) % b; };
-
--7 % 5 === -2;
-
-modulo(-7, 5) === 3;
-
-tabs.selectTabAtIndex(modulo(tabs.currentIndex - count, tabs.length));
diff --git a/documentation/js/multiple_return_values.js b/documentation/js/multiple_return_values.js
deleted file mode 100644
index 9004229786..0000000000
--- a/documentation/js/multiple_return_values.js
+++ /dev/null
@@ -1,8 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var city, forecast, ref, temp, weatherReport;
-
-weatherReport = function(location) {
- return [location, 72, "Mostly Sunny"];
-};
-
-ref = weatherReport("Berkeley, CA"), city = ref[0], temp = ref[1], forecast = ref[2];
diff --git a/documentation/js/object_comprehensions.js b/documentation/js/object_comprehensions.js
deleted file mode 100644
index b6c1c50979..0000000000
--- a/documentation/js/object_comprehensions.js
+++ /dev/null
@@ -1,18 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var age, ages, child, yearsOld;
-
-yearsOld = {
- max: 10,
- ida: 9,
- tim: 11
-};
-
-ages = (function() {
- var results;
- results = [];
- for (child in yearsOld) {
- age = yearsOld[child];
- results.push(child + " is " + age);
- }
- return results;
-})();
diff --git a/documentation/js/object_extraction.js b/documentation/js/object_extraction.js
deleted file mode 100644
index 04ff182fc2..0000000000
--- a/documentation/js/object_extraction.js
+++ /dev/null
@@ -1,13 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var city, futurists, name, ref, ref1, street;
-
-futurists = {
- sculptor: "Umberto Boccioni",
- painter: "Vladimir Burliuk",
- poet: {
- name: "F.T. Marinetti",
- address: ["Via Roma 42R", "Bellagio, Italy 22021"]
- }
-};
-
-ref = futurists.poet, name = ref.name, (ref1 = ref.address, street = ref1[0], city = ref1[1]);
diff --git a/documentation/js/objects_and_arrays.js b/documentation/js/objects_and_arrays.js
deleted file mode 100644
index 11a658dee2..0000000000
--- a/documentation/js/objects_and_arrays.js
+++ /dev/null
@@ -1,22 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var bitlist, kids, singers, song;
-
-song = ["do", "re", "mi", "fa", "so"];
-
-singers = {
- Jagger: "Rock",
- Elvis: "Roll"
-};
-
-bitlist = [1, 0, 1, 0, 0, 1, 1, 1, 0];
-
-kids = {
- brother: {
- name: "Max",
- age: 11
- },
- sister: {
- name: "Ida",
- age: 9
- }
-};
diff --git a/documentation/js/objects_reserved.js b/documentation/js/objects_reserved.js
deleted file mode 100644
index f26f126b10..0000000000
--- a/documentation/js/objects_reserved.js
+++ /dev/null
@@ -1,6 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-$('.account').attr({
- "class": 'active'
-});
-
-log(object["class"]);
diff --git a/documentation/js/overview.js b/documentation/js/overview.js
deleted file mode 100644
index aa83ec9244..0000000000
--- a/documentation/js/overview.js
+++ /dev/null
@@ -1,45 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var cubes, list, math, num, number, opposite, race, square,
- slice = [].slice;
-
-number = 42;
-
-opposite = true;
-
-if (opposite) {
- number = -42;
-}
-
-square = function(x) {
- return x * x;
-};
-
-list = [1, 2, 3, 4, 5];
-
-math = {
- root: Math.sqrt,
- square: square,
- cube: function(x) {
- return x * square(x);
- }
-};
-
-race = function() {
- var runners, winner;
- winner = arguments[0], runners = 2 <= arguments.length ? slice.call(arguments, 1) : [];
- return print(winner, runners);
-};
-
-if (typeof elvis !== "undefined" && elvis !== null) {
- alert("I knew it!");
-}
-
-cubes = (function() {
- var i, len, results;
- results = [];
- for (i = 0, len = list.length; i < len; i++) {
- num = list[i];
- results.push(math.cube(num));
- }
- return results;
-})();
diff --git a/documentation/js/parallel_assignment.js b/documentation/js/parallel_assignment.js
deleted file mode 100644
index f6d0b24a08..0000000000
--- a/documentation/js/parallel_assignment.js
+++ /dev/null
@@ -1,8 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var ref, theBait, theSwitch;
-
-theBait = 1000;
-
-theSwitch = 0;
-
-ref = [theSwitch, theBait], theBait = ref[0], theSwitch = ref[1];
diff --git a/documentation/js/patterns_and_splats.js b/documentation/js/patterns_and_splats.js
deleted file mode 100644
index 40f9aa67df..0000000000
--- a/documentation/js/patterns_and_splats.js
+++ /dev/null
@@ -1,7 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var close, contents, i, open, ref, tag,
- slice = [].slice;
-
-tag = "";
-
-ref = tag.split(""), open = ref[0], contents = 3 <= ref.length ? slice.call(ref, 1, i = ref.length - 1) : (i = 1, []), close = ref[i++];
diff --git a/documentation/js/prototypes.js b/documentation/js/prototypes.js
deleted file mode 100644
index a749e6ed5c..0000000000
--- a/documentation/js/prototypes.js
+++ /dev/null
@@ -1,4 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-String.prototype.dasherize = function() {
- return this.replace(/_/g, "-");
-};
diff --git a/documentation/js/range_comprehensions.js b/documentation/js/range_comprehensions.js
deleted file mode 100644
index 3b15064636..0000000000
--- a/documentation/js/range_comprehensions.js
+++ /dev/null
@@ -1,11 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var countdown, num;
-
-countdown = (function() {
- var i, results;
- results = [];
- for (num = i = 10; i >= 1; num = --i) {
- results.push(num);
- }
- return results;
-})();
diff --git a/documentation/js/scope.js b/documentation/js/scope.js
deleted file mode 100644
index 69378a4e2e..0000000000
--- a/documentation/js/scope.js
+++ /dev/null
@@ -1,12 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var changeNumbers, inner, outer;
-
-outer = 1;
-
-changeNumbers = function() {
- var inner;
- inner = -1;
- return outer = 10;
-};
-
-inner = changeNumbers();
diff --git a/documentation/js/slices.js b/documentation/js/slices.js
deleted file mode 100644
index fd7c4c89f8..0000000000
--- a/documentation/js/slices.js
+++ /dev/null
@@ -1,12 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var copy, end, middle, numbers, start;
-
-numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
-
-start = numbers.slice(0, 3);
-
-middle = numbers.slice(3, -2);
-
-end = numbers.slice(-2);
-
-copy = numbers.slice(0);
diff --git a/documentation/js/soaks.js b/documentation/js/soaks.js
deleted file mode 100644
index 890491b71f..0000000000
--- a/documentation/js/soaks.js
+++ /dev/null
@@ -1,4 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var ref, zip;
-
-zip = typeof lottery.drawWinner === "function" ? (ref = lottery.drawWinner().address) != null ? ref.zipcode : void 0 : void 0;
diff --git a/documentation/js/splats.js b/documentation/js/splats.js
deleted file mode 100644
index 0b9e18b661..0000000000
--- a/documentation/js/splats.js
+++ /dev/null
@@ -1,23 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var awardMedals, contenders, gold, rest, silver,
- slice = [].slice;
-
-gold = silver = rest = "unknown";
-
-awardMedals = function() {
- var first, others, second;
- first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? slice.call(arguments, 2) : [];
- gold = first;
- silver = second;
- return rest = others;
-};
-
-contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"];
-
-awardMedals.apply(null, contenders);
-
-alert("Gold: " + gold);
-
-alert("Silver: " + silver);
-
-alert("The Field: " + rest);
diff --git a/documentation/js/splices.js b/documentation/js/splices.js
deleted file mode 100644
index 1d69ed1382..0000000000
--- a/documentation/js/splices.js
+++ /dev/null
@@ -1,6 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var numbers, ref;
-
-numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
-
-[].splice.apply(numbers, [3, 4].concat(ref = [-3, -4, -5, -6])), ref;
diff --git a/documentation/js/strings.js b/documentation/js/strings.js
deleted file mode 100644
index 1c9cccccf8..0000000000
--- a/documentation/js/strings.js
+++ /dev/null
@@ -1,4 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var mobyDick;
-
-mobyDick = "Call me Ishmael. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world...";
diff --git a/documentation/js/switch.js b/documentation/js/switch.js
deleted file mode 100644
index e190aeb4e2..0000000000
--- a/documentation/js/switch.js
+++ /dev/null
@@ -1,24 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-switch (day) {
- case "Mon":
- go(work);
- break;
- case "Tue":
- go(relax);
- break;
- case "Thu":
- go(iceFishing);
- break;
- case "Fri":
- case "Sat":
- if (day === bingoDay) {
- go(bingo);
- go(dancing);
- }
- break;
- case "Sun":
- go(church);
- break;
- default:
- go(work);
-}
diff --git a/documentation/js/switch_with_no_expression.js b/documentation/js/switch_with_no_expression.js
deleted file mode 100644
index 1a571641a8..0000000000
--- a/documentation/js/switch_with_no_expression.js
+++ /dev/null
@@ -1,19 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var grade, score;
-
-score = 76;
-
-grade = (function() {
- switch (false) {
- case !(score < 60):
- return 'F';
- case !(score < 70):
- return 'D';
- case !(score < 80):
- return 'C';
- case !(score < 90):
- return 'B';
- default:
- return 'A';
- }
-})();
diff --git a/documentation/js/try.js b/documentation/js/try.js
deleted file mode 100644
index b5ab9984e5..0000000000
--- a/documentation/js/try.js
+++ /dev/null
@@ -1,12 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var error;
-
-try {
- allHellBreaksLoose();
- catsAndDogsLivingTogether();
-} catch (error1) {
- error = error1;
- print(error);
-} finally {
- cleanUp();
-}
diff --git a/documentation/js/while.js b/documentation/js/while.js
deleted file mode 100644
index b6833f8922..0000000000
--- a/documentation/js/while.js
+++ /dev/null
@@ -1,22 +0,0 @@
-// Generated by CoffeeScript 1.11.1
-var lyrics, num;
-
-if (this.studyingEconomics) {
- while (supply > demand) {
- buy();
- }
- while (!(supply > demand)) {
- sell();
- }
-}
-
-num = 6;
-
-lyrics = (function() {
- var results;
- results = [];
- while (num -= 1) {
- results.push(num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
- }
- return results;
-})();
diff --git a/examples/beautiful_code/binary_search.coffee b/examples/beautiful_code/binary_search.coffee
deleted file mode 100644
index 805aaea9ba..0000000000
--- a/examples/beautiful_code/binary_search.coffee
+++ /dev/null
@@ -1,16 +0,0 @@
-# Beautiful Code, Chapter 6.
-# The implementation of binary search that is tested.
-
-# Return the index of an element in a sorted list. (or -1, if not present)
-index = (list, target) ->
- [low, high] = [0, list.length]
- while low < high
- mid = (low + high) >> 1
- val = list[mid]
- return mid if val is target
- if val < target then low = mid + 1 else high = mid
- return -1
-
-console.log 2 is index [10, 20, 30, 40, 50], 30
-console.log 4 is index [-97, 35, 67, 88, 1200], 1200
-console.log 0 is index [0, 45, 70], 0
diff --git a/examples/beautiful_code/quicksort_runtime.coffee b/examples/beautiful_code/quicksort_runtime.coffee
deleted file mode 100644
index d48e0198eb..0000000000
--- a/examples/beautiful_code/quicksort_runtime.coffee
+++ /dev/null
@@ -1,13 +0,0 @@
-# Beautiful Code, Chapter 3.
-# Produces the expected runtime of Quicksort, for every integer from 1 to N.
-
-runtime = (N) ->
- [sum, t] = [0, 0]
- for n in [1..N]
- sum += 2 * t
- t = n - 1 + sum / n
- t
-
-console.log runtime(3) is 2.6666666666666665
-console.log runtime(5) is 7.4
-console.log runtime(8) is 16.92142857142857
diff --git a/examples/beautiful_code/regular_expression_matcher.coffee b/examples/beautiful_code/regular_expression_matcher.coffee
deleted file mode 100644
index d0e252ec2c..0000000000
--- a/examples/beautiful_code/regular_expression_matcher.coffee
+++ /dev/null
@@ -1,34 +0,0 @@
-# Beautiful Code, Chapter 1.
-# Implements a regular expression matcher that supports character matches,
-# '.', '^', '$', and '*'.
-
-# Search for the regexp anywhere in the text.
-match = (regexp, text) ->
- return match_here(regexp.slice(1), text) if regexp[0] is '^'
- while text
- return true if match_here(regexp, text)
- text = text.slice(1)
- false
-
-# Search for the regexp at the beginning of the text.
-match_here = (regexp, text) ->
- [cur, next] = [regexp[0], regexp[1]]
- if regexp.length is 0 then return true
- if next is '*' then return match_star(cur, regexp.slice(2), text)
- if cur is '$' and not next then return text.length is 0
- if text and (cur is '.' or cur is text[0]) then return match_here(regexp.slice(1), text.slice(1))
- false
-
-# Search for a kleene star match at the beginning of the text.
-match_star = (c, regexp, text) ->
- loop
- return true if match_here(regexp, text)
- return false unless text and (text[0] is c or c is '.')
- text = text.slice(1)
-
-console.log match("ex", "some text")
-console.log match("s..t", "spit")
-console.log match("^..t", "buttercup")
-console.log match("i..$", "cherries")
-console.log match("o*m", "vrooooommm!")
-console.log match("^hel*o$", "hellllllo")
diff --git a/examples/blocks.coffee b/examples/blocks.coffee
deleted file mode 100644
index d23df9f9be..0000000000
--- a/examples/blocks.coffee
+++ /dev/null
@@ -1,54 +0,0 @@
-# After wycats' http://yehudakatz.com/2010/02/07/the-building-blocks-of-ruby/
-
-# Sinatra.
-get '/hello', ->
- 'Hello World'
-
-
-# Append.
-append = (location, data) ->
- path = new Pathname location
- throw new Error "Location does not exist" unless fs.existsSync(location)
-
- File.open path, 'a', (file) ->
- file.console.log YAML.dump data
-
- data
-
-
-# Rubinius' File.open implementation.
-File.open = (path, mode, block) ->
- io = new File path, mode
-
- return io unless block
-
- try
- block io
- finally
- io.close() unless io.closed()
-
-
-# Write.
-write = (location, data) ->
- path = new Pathname location
- throw new Error "Location does not exist" unless fs.existsSync location
-
- File.open path, 'w', (file) ->
- return false if Digest.MD5.hexdigest(file.read()) is data.hash()
- file.console.log YAML.dump data
- true
-
-
-# Rails' respond_to.
-index = ->
- people = Person.find 'all'
-
- respond_to (format) ->
- format.html()
- format.xml -> render xml: people.xml()
-
-
-# Synchronization.
-synchronize = (block) ->
- lock()
- try block() finally unlock()
diff --git a/examples/code.coffee b/examples/code.coffee
deleted file mode 100644
index 88d7cf7164..0000000000
--- a/examples/code.coffee
+++ /dev/null
@@ -1,167 +0,0 @@
-# Functions:
-square = (x) -> x * x
-
-sum = (x, y) -> x + y
-
-odd = (x) -> x % 2 isnt 0
-
-even = (x) -> x % 2 is 0
-
-run_loop = ->
- fire_events((e) -> e.stopPropagation())
- listen()
- wait()
-
-# Objects:
-dense_object_literal = one: 1, two: 2, three: 3
-
-spaced_out_multiline_object =
- pi: 3.14159
- list: [1, 2, 3, 4]
- regex: /match[ing](every|thing|\/)/gi
- three: new Idea
-
- inner_obj:
- freedom: -> _.freedom()
-
-# Arrays:
-stooges = [{moe: 45}, {curly: 43}, {larry: 46}]
-
-exponents = [((x) -> x), ((x) -> x * x), ((x) -> x * x * x)]
-
-empty = []
-
-multiline = [
- 'line one'
- 'line two'
-]
-
-# Conditionals and ternaries.
-if submarine.shields_up
- full_speed_ahead()
- fire_torpedos()
-else if submarine.sinking
- abandon_ship()
-else
- run_away()
-
-eldest = if 25 > 21 then liz else marge
-
-decoration = medal_of_honor if war_hero
-
-go_to_sleep() unless coffee
-
-# Returning early:
-race = ->
- run()
- walk()
- crawl()
- return sleep() if tired
- race()
-
-# Conditional assignment:
-good or= evil
-wine and= cheese
-
-# Nested property access and calls.
-(moon.turn 360).shapes[3].move(x: 45, y: 30).position['top'].offset('x')
-
-a = b = c = 5
-
-# Embedded JavaScript.
-callback(
- `function(e) { e.stop(); }`
-)
-
-# Try/Catch/Finally/Throw.
-try
- all_hell_breaks_loose()
- dogs_and_cats_living_together()
- throw "up"
-catch error
- print error
-finally
- clean_up()
-
-try all_hell_breaks_loose() catch error then print(error) finally clean_up()
-
-# While loops, break and continue.
-while demand > supply
- sell()
- restock()
-
-while supply > demand then buy()
-
-loop
- break if broken
- continue if continuing
-
-# Unary operators.
-!!true
-
-# Lexical scoping.
-v_1 = 5
-change_a_and_set_b = ->
- v_1 = 10
- v_2 = 15
-v_2 = 20
-
-# Array comprehensions.
-supper = food.capitalize() for food in ['toast', 'cheese', 'wine']
-
-drink bottle for bottle, i in ['soda', 'wine', 'lemonade'] when even i
-
-# Switch statements ("else" serves as a default).
-activity = switch day
- when "Tuesday" then eat_breakfast()
- when "Sunday" then go_to_church()
- when "Saturday" then go_to_the_park()
- when "Wednesday"
- if day is bingo_day
- go_to_bingo()
- else
- eat_breakfast()
- go_to_work()
- eat_dinner()
- else go_to_work()
-
-# Semicolons can optionally be used instead of newlines.
-wednesday = -> eat_breakfast(); go_to_work(); eat_dinner()
-
-# Multiline strings with inner quotes.
-story = "Lorem ipsum dolor \"sit\" amet, consectetuer adipiscing elit,
- sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna
- aliquam erat volutpat. Ut wisi enim ad."
-
-# Inheritance and calling super.
-class Animal
- (@name) ->
-
- move: (meters) ->
- alert this.name + " moved " + meters + "m."
-
-class Snake extends Animal
- move: ->
- alert 'Slithering...'
- super 5
-
-class Horse extends Animal
- move: ->
- alert 'Galloping...'
- super 45
-
-sam = new Snake "Sammy the Snake"
-tom = new Horse "Tommy the Horse"
-
-sam.move()
-tom.move()
-
-# Numbers.
-a_googol = 1e100
-hex = 0xff0000
-negative = -1.0
-infinity = Infinity
-nan = NaN
-
-# Deleting.
-delete secret.identity
diff --git a/examples/computer_science/README b/examples/computer_science/README
deleted file mode 100644
index 1046f9f9b5..0000000000
--- a/examples/computer_science/README
+++ /dev/null
@@ -1,4 +0,0 @@
-Ported from Nicholas Zakas' collection of computer science fundamentals, written
-in JavaScript. Originals available here:
-
-http://github.com/nzakas/computer-science-in-javascript
diff --git a/examples/computer_science/binary_search.coffee b/examples/computer_science/binary_search.coffee
deleted file mode 100644
index f8215b06f4..0000000000
--- a/examples/computer_science/binary_search.coffee
+++ /dev/null
@@ -1,25 +0,0 @@
-# Uses a binary search algorithm to locate a value in the specified array.
-binary_search = (items, value) ->
-
- start = 0
- stop = items.length - 1
- pivot = Math.floor (start + stop) / 2
-
- while items[pivot] isnt value and start < stop
-
- # Adjust the search area.
- stop = pivot - 1 if value < items[pivot]
- start = pivot + 1 if value > items[pivot]
-
- # Recalculate the pivot.
- pivot = Math.floor (stop + start) / 2
-
- # Make sure we've found the correct value.
- if items[pivot] is value then pivot else -1
-
-
-# Test the function.
-console.log 2 is binary_search [10, 20, 30, 40, 50], 30
-console.log 4 is binary_search [-97, 35, 67, 88, 1200], 1200
-console.log 0 is binary_search [0, 45, 70], 0
-console.log -1 is binary_search [0, 45, 70], 10
diff --git a/examples/computer_science/bubble_sort.coffee b/examples/computer_science/bubble_sort.coffee
deleted file mode 100644
index e84a92cf94..0000000000
--- a/examples/computer_science/bubble_sort.coffee
+++ /dev/null
@@ -1,11 +0,0 @@
-# A bubble sort implementation, sorting the given array in-place.
-bubble_sort = (list) ->
- for i in [0...list.length]
- for j in [0...list.length - i] when list[j] > list[j + 1]
- [list[j], list[j+1]] = [list[j + 1], list[j]]
- list
-
-
-# Test the function.
-console.log bubble_sort([3, 2, 1]).join(' ') is '1 2 3'
-console.log bubble_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9'
diff --git a/examples/computer_science/linked_list.coffee b/examples/computer_science/linked_list.coffee
deleted file mode 100644
index 3e4ee6c8cc..0000000000
--- a/examples/computer_science/linked_list.coffee
+++ /dev/null
@@ -1,108 +0,0 @@
-# "Classic" linked list implementation that doesn't keep track of its size.
-class LinkedList
-
- constructor: ->
- @_head = null # Pointer to the first item in the list.
-
-
- # Appends some data to the end of the list. This method traverses the existing
- # list and places the value at the end in a new node.
- add: (data) ->
-
- # Create a new node object to wrap the data.
- node = data: data, next: null
-
- current = @_head or= node
-
- if @_head isnt node
- current = current.next while current.next
- current.next = node
-
- this
-
-
- # Retrieves the data at the given position in the list.
- item: (index) ->
-
- # Check for out-of-bounds values.
- return null if index < 0
-
- current = @_head or null
- i = -1
-
- # Advance through the list.
- current = current.next while current and index > ++i
-
- # Return null if we've reached the end.
- current and current.data
-
-
- # Remove the item from the given location in the list.
- remove: (index) ->
-
- # Check for out-of-bounds values.
- return null if index < 0
-
- current = @_head or null
- i = -1
-
- # Special case: removing the first item.
- if index is 0
- @_head = current.next
- else
-
- # Find the right location.
- [previous, current] = [current, current.next] while index > ++i
-
- # Skip over the item to remove.
- previous.next = current.next
-
- # Return the value.
- current and current.data
-
-
- # Calculate the number of items in the list.
- size: ->
- current = @_head
- count = 0
-
- while current
- count += 1
- current = current.next
-
- count
-
-
- # Convert the list into an array.
- toArray: ->
- result = []
- current = @_head
-
- while current
- result.push current.data
- current = current.next
-
- result
-
-
- # The string representation of the linked list.
- toString: -> @toArray().toString()
-
-
-# Tests.
-list = new LinkedList
-
-list.add("Hi")
-console.log list.size() is 1
-console.log list.item(0) is "Hi"
-console.log list.item(1) is null
-
-list = new LinkedList
-list.add("zero").add("one").add("two")
-console.log list.size() is 3
-console.log list.item(2) is "two"
-console.log list.remove(1) is "one"
-console.log list.item(0) is "zero"
-console.log list.item(1) is "two"
-console.log list.size() is 2
-console.log list.item(-10) is null
diff --git a/examples/computer_science/luhn_algorithm.coffee b/examples/computer_science/luhn_algorithm.coffee
deleted file mode 100644
index bea41f4032..0000000000
--- a/examples/computer_science/luhn_algorithm.coffee
+++ /dev/null
@@ -1,36 +0,0 @@
-# Use the Luhn algorithm to validate a numeric identifier, such as credit card
-# numbers, national insurance numbers, etc.
-# See: http://en.wikipedia.org/wiki/Luhn_algorithm
-
-is_valid_identifier = (identifier) ->
-
- sum = 0
- alt = false
-
- for c in identifier by -1
-
- # Get the next digit.
- num = parseInt c, 10
-
- # If it's not a valid number, abort.
- return false if isNaN num
-
- # If it's an alternate number...
- if alt
- num *= 2
- num = (num % 10) + 1 if num > 9
-
- # Flip the alternate bit.
- alt = !alt
-
- # Add to the rest of the sum.
- sum += num
-
- # Determine if it's valid.
- sum % 10 is 0
-
-
-# Tests.
-console.log is_valid_identifier("49927398716") is true
-console.log is_valid_identifier("4408041234567893") is true
-console.log is_valid_identifier("4408041234567890") is false
diff --git a/examples/computer_science/merge_sort.coffee b/examples/computer_science/merge_sort.coffee
deleted file mode 100644
index 13e089f38e..0000000000
--- a/examples/computer_science/merge_sort.coffee
+++ /dev/null
@@ -1,18 +0,0 @@
-# Sorts an array in ascending natural order using merge sort.
-merge_sort = (list) ->
-
- return list if list.length is 1
-
- pivot = Math.floor list.length / 2
- left = merge_sort list.slice 0, pivot
- right = merge_sort list.slice pivot
-
- result = while left.length and right.length
- if left[0] < right[0] then left.shift() else right.shift()
-
- result.concat(left).concat(right)
-
-
-# Test the function.
-console.log merge_sort([3, 2, 1]).join(' ') is '1 2 3'
-console.log merge_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9'
diff --git a/examples/computer_science/selection_sort.coffee b/examples/computer_science/selection_sort.coffee
deleted file mode 100644
index 826c7d501e..0000000000
--- a/examples/computer_science/selection_sort.coffee
+++ /dev/null
@@ -1,23 +0,0 @@
-# An in-place selection sort.
-selection_sort = (list) ->
- len = list.length
-
- # For each item in the list.
- for i in [0...len]
-
- # Set the minimum to this position.
- min = i
-
- # Check the rest of the array to see if anything is smaller.
- min = k for v, k in list[i+1...] when v < list[min]
-
- # Swap if a smaller item has been found.
- [list[i], list[min]] = [list[min], list[i]] if i isnt min
-
- # The list is now sorted.
- list
-
-
-# Test the function.
-console.log selection_sort([3, 2, 1]).join(' ') is '1 2 3'
-console.log selection_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9'
diff --git a/examples/custom_repl.coffee b/examples/custom_repl.coffee
deleted file mode 100644
index db944d2ace..0000000000
--- a/examples/custom_repl.coffee
+++ /dev/null
@@ -1,20 +0,0 @@
-###
-Example of embedding the CoffeeScript REPL, strikingly similar to the Node REPL.
-###
-
-# Require 'coffee-script/repl' to import the repl module
-repl = require '../repl'
-
-console.log 'Custom REPL! Type `sayHi()` to see what it does!'
-
-# Start the REPL with your configuration
-r = repl.start
- prompt: 'my-repl> '
-
-# Fields added to the context object are exposed as variables in the REPL
-r.context.sayHi = -> console.log 'Hello'
-
-# An exit event is emitted when the user exits the REPL
-r.on 'exit', ->
- console.log 'Bye!'
- process.exit()
diff --git a/examples/poignant.coffee b/examples/poignant.coffee
deleted file mode 100644
index eb129b0d86..0000000000
--- a/examples/poignant.coffee
+++ /dev/null
@@ -1,181 +0,0 @@
-# Examples from the Poignant Guide.
-# These are examples of syntax differences between CoffeeScript and Ruby,
-# they won't run.
-
-# ['toast', 'cheese', 'wine'].each { |food| print food.capitalize }
-
-print food.capitalize() for food in ['toast', 'wine', 'cheese']
-
-
-
-
-# class LotteryTicket
-# def picks; @picks; end
-# def picks=(var); @picks = var; end
-# def purchased; @purchased; end
-# def purchased=(var); @purchased = var; end
-# end
-
-LotteryTicket =
- get_picks: -> @picks
- set_picks: (@picks) ->
- get_purchased: -> @purchase
- set_purchased: (@purchased) ->
-
-
-
-# class << LotteryDraw
-# def play
-# result = LotteryTicket.new_random
-# winners = {}
-# @@tickets.each do |buyer, ticket_list|
-# ticket_list.each do |ticket|
-# score = ticket.score( result )
-# next if score.zero?
-# winners[buyer] ||= []
-# winners[buyer] << [ ticket, score ]
-# end
-# end
-# @@tickets.clear
-# winners
-# end
-# end
-
-LotteryDraw =
- play: ->
- result = LotteryTicket.new_random()
- winners = {}
- for buyer, ticketList of @tickets
- for ticket in ticketList when (score = ticket.score result) isnt 0
- (winners[buyer] or= []).push [ticket, score]
- @tickets = {}
- winners
-
-
-
-# module WishScanner
-# def scan_for_a_wish
-# wish = self.read.detect do |thought|
-# thought.index( 'wish: ' ) == 0
-# end
-# wish.gsub( 'wish: ', '' )
-# end
-# end
-
-WishScanner =
- scan_for_a_wish: ->
- wish = @read().detect (thought) -> thought.indexOf('wish: ') is 0
- wish.replace 'wish: ', ''
-
-
-
-# class Creature
-#
-# # This method applies a hit taken during a fight.
-# def hit( damage )
-# p_up = rand( charisma )
-# if p_up % 9 == 7
-# @life += p_up / 4
-# console.log "[#{ self.class } magick powers up #{ p_up }!]"
-# end
-# @life -= damage
-# console.log "[#{ self.class } has died.]" if @life <= 0
-# end
-#
-# # This method takes one turn in a fight.
-# def fight( enemy, weapon )
-# if life <= 0
-# console.log "[#{ self.class } is too dead to fight!]"
-# return
-# end
-#
-# # Attack the opponent
-# your_hit = rand( strength + weapon )
-# console.log "[You hit with #{ your_hit } points of damage!]"
-# enemy.hit( your_hit )
-#
-# # Retaliation
-# p enemy
-# if enemy.life > 0
-# enemy_hit = rand( enemy.strength + enemy.weapon )
-# console.log "[Your enemy hit with #{ enemy_hit } points of damage!]"
-# self.hit( enemy_hit )
-# end
-# end
-#
-# end
-
-Creature =
-
- # This method applies a hit taken during a fight.
- hit: (damage) ->
- p_up = Math.rand @charisma
- if p_up % 9 is 7
- @life += p_up / 4
- console.log "[#{@name} magick powers up #{p_up}!]"
- @life -= damage
- if @life <= 0 then console.log "[#{@name} has died.]"
-
- # This method takes one turn in a fight.
- fight: (enemy, weapon) ->
- return console.log "[#{@name} is too dead to fight!]" if @life <= 0
-
- # Attack the opponent.
- your_hit = Math.rand @strength + weapon
- console.log "[You hit with #{your_hit}points of damage!]"
- enemy.hit your_hit
-
- # Retaliation.
- console.log enemy
- if enemy.life > 0
- enemy_hit = Math.rand enemy.strength + enemy.weapon
- console.log "[Your enemy hit with #{enemy_hit}points of damage!]"
- @hit enemy_hit
-
-
-
-# # Get evil idea and swap in code words
-# print "Enter your new idea: "
-# idea = gets
-# code_words.each do |real, code|
-# idea.gsub!( real, code )
-# end
-#
-# # Save the jibberish to a new file
-# print "File encoded. Please enter a name for this idea: "
-# idea_name = gets.strip
-# File::open( "idea-" + idea_name + ".txt", "w" ) do |f|
-# f << idea
-# end
-
-# Get evil idea and swap in code words
-print "Enter your new idea: "
-idea = gets()
-code_words.each (real, code) -> idea.replace(real, code)
-
-# Save the jibberish to a new file
-print "File encoded. Please enter a name for this idea: "
-idea_name = gets().strip()
-File.open "idea-#{idea_name}.txt", 'w', (file) -> file.write idea
-
-
-
-# def wipe_mutterings_from( sentence )
-# unless sentence.respond_to? :include?
-# raise ArgumentError,
-# "cannot wipe mutterings from a #{ sentence.class }"
-# end
-# while sentence.include? '('
-# open = sentence.index( '(' )
-# close = sentence.index( ')', open )
-# sentence[open..close] = '' if close
-# end
-# end
-
-wipe_mutterings_from = (sentence) ->
- throw new Error "cannot wipe mutterings" unless sentence.indexOf
- while '(' in sentence
- open = sentence.indexOf('(')
- close = sentence.indexOf(')')
- sentence = "#{sentence[0...open]}#{sentence[close + 1..]}"
- sentence
diff --git a/examples/potion.coffee b/examples/potion.coffee
deleted file mode 100644
index 88c0462fa9..0000000000
--- a/examples/potion.coffee
+++ /dev/null
@@ -1,206 +0,0 @@
-# Examples from _why's Potion, the Readme and "Potion: A Short Pamphlet".
-
-# 5 times: "Odelay!" print.
-
-print "Odelay!" for i in [1..5]
-
-
-# add = (x, y): x + y.
-# add(2, 4) string print
-
-add = (x, y) -> x + y
-print add 2, 4
-
-
-# loop: 'quaff' print.
-
-loop print 'quaff'
-
-
-# ('cheese', 'bread', 'mayo') at (1) print
-
-print ['cheese', 'bread', 'mayo'][1]
-
-
-# (language='Potion', pointless=true) at (key='language') print
-
-print {language: 'Potion', pointless: true}['language']
-
-
-# minus = (x, y): x - y.
-# minus (y=10, x=6)
-
-minus = (x, y) -> x - y
-minus 6, 10
-
-
-# foods = ('cheese', 'bread', 'mayo')
-# foods (2)
-
-foods = ['cheese', 'bread', 'mayo']
-foods[2]
-
-
-# (dog='canine', cat='feline', fox='vulpine') each (key, val):
-# (key, ' is a ', val) join print.
-
-for key, val of {dog: 'canine', cat: 'feline', fox: 'vulpine'}
- print "#{key} is a #{val}"
-
-
-# Person = class: /name, /age, /sex.
-# Person print = ():
-# ('My name is ', /name, '.') join print.
-
-class Person
- print: ->
- print "My name is #{@name}."
-
-
-# p = Person ()
-# p /name string print
-
-p = new Person
-print p.name
-
-
-# Policeman = Person class (rank): /rank = rank.
-# Policeman print = ():
-# ('My name is ', /name, ' and I'm a ', /rank, '.') join print.
-#
-# Policeman ('Constable') print
-
-class Policeman extends Person
- (@rank) ->
-
- print: ->
- print "My name is #{@name} and I'm a #{@rank}."
-
-print new Policeman 'Constable'
-
-
-# app = [window (width=200, height=400)
-# [para 'Welcome.', button 'OK']]
-# app first name
-
-app =
- window:
- width: 200
- height: 200
- para: 'Welcome.'
- button: 'OK'
-
-app.window
-
-
-# x = 1
-# y = 2
-#
-# x = 1, y = 2
-
-x = 1
-y = 2
-
-x = 1; y = 2
-
-
-# table = (language='Potion'
-# pointless=true)
-
-table =
- language: 'Potion'
- pointless: yes
-
-
-# # this foul business...
-# String length = (): 10.
-
-# this foul business...
-String::length = -> 10
-
-
-# block = :
-# 'potion' print.
-
-block = ->
- print 'potion'
-
-
-# if (age > 100): 'ancient'.
-
-if age > 100 then 'ancient'
-
-
-# author =
-# if (title == 'Jonathan Strange & Mr. Norrell'):
-# 'Susanna Clarke'.
-# elsif (title == 'The Star Diaries'):
-# 'Stanislaw Lem'.
-# elsif (title == 'The Slynx'):
-# 'Tatyana Tolstaya'.
-# else:
-# '... probably Philip K. Dick'.
-
-switch author
- when 'Jonathan Strange & Mr. Norrell'
- 'Susanna Clarke'
- when 'The Star Diaries'
- 'Stanislaw Lem'
- when 'The Slynx'
- 'Tatyana Tolstaya'
- else
- '... probably Philip K. Dick'
-
-
-# count = 8
-# while (count > 0):
-# 'quaff' print
-# count--.
-
-count = 8
-while count > 0
- print 'quaff'
- count--
-
-
-# 1 to 5 (a):
-# a string print.
-
-print a for a in [1..5]
-
-
-# if (3 ?gender):
-# "Huh? Numbers are sexed? That's amazing." print.
-
-if 3.gender?
- print "Huh? Numbers are sexed? That's amazing."
-
-
-# HomePage get = (url):
-# session = url query ? at ('session').
-
-HomePage::get = (url) ->
- session = url.query?.session
-
-
-# BTree = class: /left, /right.
-# b = BTree ()
-# b /left = BTree ()
-# b /right = BTree ()
-
-BTree = ->
-b = new BTree
-b.left = new BTree
-b.right = new BTree
-
-
-# BTree = class: /left, /right.
-# b = BTree ()
-#
-# if (b ? /left):
-# 'left path found!' print.
-
-BTree = ->
-b = new BTree
-
-print 'left path found!' if b.left?
diff --git a/examples/underscore.coffee b/examples/underscore.coffee
deleted file mode 100644
index 302913cdda..0000000000
--- a/examples/underscore.coffee
+++ /dev/null
@@ -1,682 +0,0 @@
-# **Underscore.coffee
-# (c) 2011 Jeremy Ashkenas, DocumentCloud Inc.**
-# Underscore is freely distributable under the terms of the
-# [MIT license](http://en.wikipedia.org/wiki/MIT_License).
-# Portions of Underscore are inspired by or borrowed from
-# [Prototype.js](http://prototypejs.org/api), Oliver Steele's
-# [Functional](http://osteele.com), and John Resig's
-# [Micro-Templating](http://ejohn.org).
-# For all details and documentation:
-# http://documentcloud.github.com/underscore/
-
-
-# Baseline setup
-# --------------
-
-# Establish the root object, `window` in the browser, or `global` on the server.
-root = this
-
-
-# Save the previous value of the `_` variable.
-previousUnderscore = root._
-
-
-# Establish the object that gets thrown to break out of a loop iteration.
-# `StopIteration` is SOP on Mozilla.
-breaker = if typeof(StopIteration) is 'undefined' then '__break__' else StopIteration
-
-
-# Helper function to escape **RegExp** contents, because JS doesn't have one.
-escapeRegExp = (string) -> string.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1')
-
-
-# Save bytes in the minified (but not gzipped) version:
-ArrayProto = Array.prototype
-ObjProto = Object.prototype
-
-
-# Create quick reference variables for speed access to core prototypes.
-slice = ArrayProto.slice
-unshift = ArrayProto.unshift
-toString = ObjProto.toString
-hasOwnProperty = ObjProto.hasOwnProperty
-propertyIsEnumerable = ObjProto.propertyIsEnumerable
-
-
-# All **ECMA5** native implementations we hope to use are declared here.
-nativeForEach = ArrayProto.forEach
-nativeMap = ArrayProto.map
-nativeReduce = ArrayProto.reduce
-nativeReduceRight = ArrayProto.reduceRight
-nativeFilter = ArrayProto.filter
-nativeEvery = ArrayProto.every
-nativeSome = ArrayProto.some
-nativeIndexOf = ArrayProto.indexOf
-nativeLastIndexOf = ArrayProto.lastIndexOf
-nativeIsArray = Array.isArray
-nativeKeys = Object.keys
-
-
-# Create a safe reference to the Underscore object for use below.
-_ = (obj) -> new wrapper(obj)
-
-
-# Export the Underscore object for **CommonJS**.
-if typeof(exports) != 'undefined' then exports._ = _
-
-
-# Export Underscore to global scope.
-root._ = _
-
-
-# Current version.
-_.VERSION = '1.1.0'
-
-
-# Collection Functions
-# --------------------
-
-# The cornerstone, an **each** implementation.
-# Handles objects implementing **forEach**, arrays, and raw objects.
-_.each = (obj, iterator, context) ->
- try
- if nativeForEach and obj.forEach is nativeForEach
- obj.forEach iterator, context
- else if _.isNumber obj.length
- iterator.call context, obj[i], i, obj for i in [0...obj.length]
- else
- iterator.call context, val, key, obj for own key, val of obj
- catch e
- throw e if e isnt breaker
- obj
-
-
-# Return the results of applying the iterator to each element. Use JavaScript
-# 1.6's version of **map**, if possible.
-_.map = (obj, iterator, context) ->
- return obj.map(iterator, context) if nativeMap and obj.map is nativeMap
- results = []
- _.each obj, (value, index, list) ->
- results.push iterator.call context, value, index, list
- results
-
-
-# **Reduce** builds up a single result from a list of values. Also known as
-# **inject**, or **foldl**. Uses JavaScript 1.8's version of **reduce**, if possible.
-_.reduce = (obj, iterator, memo, context) ->
- if nativeReduce and obj.reduce is nativeReduce
- iterator = _.bind iterator, context if context
- return obj.reduce iterator, memo
- _.each obj, (value, index, list) ->
- memo = iterator.call context, memo, value, index, list
- memo
-
-
-# The right-associative version of **reduce**, also known as **foldr**. Uses
-# JavaScript 1.8's version of **reduceRight**, if available.
-_.reduceRight = (obj, iterator, memo, context) ->
- if nativeReduceRight and obj.reduceRight is nativeReduceRight
- iterator = _.bind iterator, context if context
- return obj.reduceRight iterator, memo
- reversed = _.clone(_.toArray(obj)).reverse()
- _.reduce reversed, iterator, memo, context
-
-
-# Return the first value which passes a truth test.
-_.detect = (obj, iterator, context) ->
- result = null
- _.each obj, (value, index, list) ->
- if iterator.call context, value, index, list
- result = value
- _.breakLoop()
- result
-
-
-# Return all the elements that pass a truth test. Use JavaScript 1.6's
-# **filter**, if it exists.
-_.filter = (obj, iterator, context) ->
- return obj.filter iterator, context if nativeFilter and obj.filter is nativeFilter
- results = []
- _.each obj, (value, index, list) ->
- results.push value if iterator.call context, value, index, list
- results
-
-
-# Return all the elements for which a truth test fails.
-_.reject = (obj, iterator, context) ->
- results = []
- _.each obj, (value, index, list) ->
- results.push value if not iterator.call context, value, index, list
- results
-
-
-# Determine whether all of the elements match a truth test. Delegate to
-# JavaScript 1.6's **every**, if it is present.
-_.every = (obj, iterator, context) ->
- iterator ||= _.identity
- return obj.every iterator, context if nativeEvery and obj.every is nativeEvery
- result = true
- _.each obj, (value, index, list) ->
- _.breakLoop() unless (result = result and iterator.call(context, value, index, list))
- result
-
-
-# Determine if at least one element in the object matches a truth test. Use
-# JavaScript 1.6's **some**, if it exists.
-_.some = (obj, iterator, context) ->
- iterator ||= _.identity
- return obj.some iterator, context if nativeSome and obj.some is nativeSome
- result = false
- _.each obj, (value, index, list) ->
- _.breakLoop() if (result = iterator.call(context, value, index, list))
- result
-
-
-# Determine if a given value is included in the array or object,
-# based on `===`.
-_.include = (obj, target) ->
- return _.indexOf(obj, target) isnt -1 if nativeIndexOf and obj.indexOf is nativeIndexOf
- return true for own key, val of obj when val is target
- false
-
-
-# Invoke a method with arguments on every item in a collection.
-_.invoke = (obj, method) ->
- args = _.rest arguments, 2
- (if method then val[method] else val).apply(val, args) for val in obj
-
-
-# Convenience version of a common use case of **map**: fetching a property.
-_.pluck = (obj, key) ->
- _.map(obj, (val) -> val[key])
-
-
-# Return the maximum item or (item-based computation).
-_.max = (obj, iterator, context) ->
- return Math.max.apply(Math, obj) if not iterator and _.isArray(obj)
- result = computed: -Infinity
- _.each obj, (value, index, list) ->
- computed = if iterator then iterator.call(context, value, index, list) else value
- computed >= result.computed and (result = {value: value, computed: computed})
- result.value
-
-
-# Return the minimum element (or element-based computation).
-_.min = (obj, iterator, context) ->
- return Math.min.apply(Math, obj) if not iterator and _.isArray(obj)
- result = computed: Infinity
- _.each obj, (value, index, list) ->
- computed = if iterator then iterator.call(context, value, index, list) else value
- computed < result.computed and (result = {value: value, computed: computed})
- result.value
-
-
-# Sort the object's values by a criterion produced by an iterator.
-_.sortBy = (obj, iterator, context) ->
- _.pluck(((_.map obj, (value, index, list) ->
- {value: value, criteria: iterator.call(context, value, index, list)}
- ).sort((left, right) ->
- a = left.criteria; b = right.criteria
- if a < b then -1 else if a > b then 1 else 0
- )), 'value')
-
-
-# Use a comparator function to figure out at what index an object should
-# be inserted so as to maintain order. Uses binary search.
-_.sortedIndex = (array, obj, iterator) ->
- iterator ||= _.identity
- low = 0
- high = array.length
- while low < high
- mid = (low + high) >> 1
- if iterator(array[mid]) < iterator(obj) then low = mid + 1 else high = mid
- low
-
-
-# Convert anything iterable into a real, live array.
-_.toArray = (iterable) ->
- return [] if (!iterable)
- return iterable.toArray() if (iterable.toArray)
- return iterable if (_.isArray(iterable))
- return slice.call(iterable) if (_.isArguments(iterable))
- _.values(iterable)
-
-
-# Return the number of elements in an object.
-_.size = (obj) -> _.toArray(obj).length
-
-
-# Array Functions
-# ---------------
-
-# Get the first element of an array. Passing `n` will return the first N
-# values in the array. Aliased as **head**. The `guard` check allows it to work
-# with **map**.
-_.first = (array, n, guard) ->
- if n and not guard then slice.call(array, 0, n) else array[0]
-
-
-# Returns everything but the first entry of the array. Aliased as **tail**.
-# Especially useful on the arguments object. Passing an `index` will return
-# the rest of the values in the array from that index onward. The `guard`
-# check allows it to work with **map**.
-_.rest = (array, index, guard) ->
- slice.call(array, if _.isUndefined(index) or guard then 1 else index)
-
-
-# Get the last element of an array.
-_.last = (array) -> array[array.length - 1]
-
-
-# Trim out all falsy values from an array.
-_.compact = (array) -> item for item in array when item
-
-
-# Return a completely flattened version of an array.
-_.flatten = (array) ->
- _.reduce array, (memo, value) ->
- return memo.concat(_.flatten(value)) if _.isArray value
- memo.push value
- memo
- , []
-
-
-# Return a version of the array that does not contain the specified value(s).
-_.without = (array) ->
- values = _.rest arguments
- val for val in _.toArray(array) when not _.include values, val
-
-
-# Produce a duplicate-free version of the array. If the array has already
-# been sorted, you have the option of using a faster algorithm.
-_.uniq = (array, isSorted) ->
- memo = []
- for el, i in _.toArray array
- memo.push el if i is 0 || (if isSorted is true then _.last(memo) isnt el else not _.include(memo, el))
- memo
-
-
-# Produce an array that contains every item shared between all the
-# passed-in arrays.
-_.intersect = (array) ->
- rest = _.rest arguments
- _.select _.uniq(array), (item) ->
- _.all rest, (other) ->
- _.indexOf(other, item) >= 0
-
-
-# Zip together multiple lists into a single array -- elements that share
-# an index go together.
-_.zip = ->
- length = _.max _.pluck arguments, 'length'
- results = new Array length
- for i in [0...length]
- results[i] = _.pluck arguments, String i
- results
-
-
-# If the browser doesn't supply us with **indexOf** (I'm looking at you, MSIE),
-# we need this function. Return the position of the first occurrence of an
-# item in an array, or -1 if the item is not included in the array.
-_.indexOf = (array, item) ->
- return array.indexOf item if nativeIndexOf and array.indexOf is nativeIndexOf
- i = 0; l = array.length
- while l - i
- if array[i] is item then return i else i++
- -1
-
-
-# Provide JavaScript 1.6's **lastIndexOf**, delegating to the native function,
-# if possible.
-_.lastIndexOf = (array, item) ->
- return array.lastIndexOf(item) if nativeLastIndexOf and array.lastIndexOf is nativeLastIndexOf
- i = array.length
- while i
- if array[i] is item then return i else i--
- -1
-
-
-# Generate an integer Array containing an arithmetic progression. A port of
-# [the native Python **range** function](http://docs.python.org/library/functions.html#range).
-_.range = (start, stop, step) ->
- a = arguments
- solo = a.length <= 1
- i = start = if solo then 0 else a[0]
- stop = if solo then a[0] else a[1]
- step = a[2] or 1
- len = Math.ceil((stop - start) / step)
- return [] if len <= 0
- range = new Array len
- idx = 0
- loop
- return range if (if step > 0 then i - stop else stop - i) >= 0
- range[idx] = i
- idx++
- i+= step
-
-
-# Function Functions
-# ------------------
-
-# Create a function bound to a given object (assigning `this`, and arguments,
-# optionally). Binding with arguments is also known as **curry**.
-_.bind = (func, obj) ->
- args = _.rest arguments, 2
- -> func.apply obj or root, args.concat arguments
-
-
-# Bind all of an object's methods to that object. Useful for ensuring that
-# all callbacks defined on an object belong to it.
-_.bindAll = (obj) ->
- funcs = if arguments.length > 1 then _.rest(arguments) else _.functions(obj)
- _.each funcs, (f) -> obj[f] = _.bind obj[f], obj
- obj
-
-
-# Delays a function for the given number of milliseconds, and then calls
-# it with the arguments supplied.
-_.delay = (func, wait) ->
- args = _.rest arguments, 2
- setTimeout((-> func.apply(func, args)), wait)
-
-
-# Memoize an expensive function by storing its results.
-_.memoize = (func, hasher) ->
- memo = {}
- hasher or= _.identity
- ->
- key = hasher.apply this, arguments
- return memo[key] if key of memo
- memo[key] = func.apply this, arguments
-
-
-# Defers a function, scheduling it to run after the current call stack has
-# cleared.
-_.defer = (func) ->
- _.delay.apply _, [func, 1].concat _.rest arguments
-
-
-# Returns the first function passed as an argument to the second,
-# allowing you to adjust arguments, run code before and after, and
-# conditionally execute the original function.
-_.wrap = (func, wrapper) ->
- -> wrapper.apply wrapper, [func].concat arguments
-
-
-# Returns a function that is the composition of a list of functions, each
-# consuming the return value of the function that follows.
-_.compose = ->
- funcs = arguments
- ->
- args = arguments
- for i in [funcs.length - 1..0] by -1
- args = [funcs[i].apply(this, args)]
- args[0]
-
-
-# Object Functions
-# ----------------
-
-# Retrieve the names of an object's properties.
-_.keys = nativeKeys or (obj) ->
- return _.range 0, obj.length if _.isArray(obj)
- key for key, val of obj
-
-
-# Retrieve the values of an object's properties.
-_.values = (obj) ->
- _.map obj, _.identity
-
-
-# Return a sorted list of the function names available in Underscore.
-_.functions = (obj) ->
- _.filter(_.keys(obj), (key) -> _.isFunction(obj[key])).sort()
-
-
-# Extend a given object with all of the properties in a source object.
-_.extend = (obj) ->
- for source in _.rest(arguments)
- obj[key] = val for key, val of source
- obj
-
-
-# Create a (shallow-cloned) duplicate of an object.
-_.clone = (obj) ->
- return obj.slice 0 if _.isArray obj
- _.extend {}, obj
-
-
-# Invokes interceptor with the obj, and then returns obj.
-# The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.
-_.tap = (obj, interceptor) ->
- interceptor obj
- obj
-
-
-# Perform a deep comparison to check if two objects are equal.
-_.isEqual = (a, b) ->
- # Check object identity.
- return true if a is b
- # Different types?
- atype = typeof(a); btype = typeof(b)
- return false if atype isnt btype
- # Basic equality test (watch out for coercions).
- return true if `a == b`
- # One is falsy and the other truthy.
- return false if (!a and b) or (a and !b)
- # One of them implements an `isEqual()`?
- return a.isEqual(b) if a.isEqual
- # Check dates' integer values.
- return a.getTime() is b.getTime() if _.isDate(a) and _.isDate(b)
- # Both are NaN?
- return false if _.isNaN(a) and _.isNaN(b)
- # Compare regular expressions.
- if _.isRegExp(a) and _.isRegExp(b)
- return a.source is b.source and
- a.global is b.global and
- a.ignoreCase is b.ignoreCase and
- a.multiline is b.multiline
- # If a is not an object by this point, we can't handle it.
- return false if atype isnt 'object'
- # Check for different array lengths before comparing contents.
- return false if a.length and (a.length isnt b.length)
- # Nothing else worked, deep compare the contents.
- aKeys = _.keys(a); bKeys = _.keys(b)
- # Different object sizes?
- return false if aKeys.length isnt bKeys.length
- # Recursive comparison of contents.
- return false for key, val of a when !(key of b) or !_.isEqual(val, b[key])
- true
-
-
-# Is a given array or object empty?
-_.isEmpty = (obj) ->
- return obj.length is 0 if _.isArray(obj) or _.isString(obj)
- return false for own key of obj
- true
-
-
-# Is a given value a DOM element?
-_.isElement = (obj) -> obj and obj.nodeType is 1
-
-
-# Is a given value an array?
-_.isArray = nativeIsArray or (obj) -> !!(obj and obj.concat and obj.unshift and not obj.callee)
-
-
-# Is a given variable an arguments object?
-_.isArguments = (obj) -> obj and obj.callee
-
-
-# Is the given value a function?
-_.isFunction = (obj) -> !!(obj and obj.constructor and obj.call and obj.apply)
-
-
-# Is the given value a string?
-_.isString = (obj) -> !!(obj is '' or (obj and obj.charCodeAt and obj.substr))
-
-
-# Is a given value a number?
-_.isNumber = (obj) -> (obj is +obj) or toString.call(obj) is '[object Number]'
-
-
-# Is a given value a boolean?
-_.isBoolean = (obj) -> obj is true or obj is false
-
-
-# Is a given value a Date?
-_.isDate = (obj) -> !!(obj and obj.getTimezoneOffset and obj.setUTCFullYear)
-
-
-# Is the given value a regular expression?
-_.isRegExp = (obj) -> !!(obj and obj.exec and (obj.ignoreCase or obj.ignoreCase is false))
-
-
-# Is the given value NaN -- this one is interesting. `NaN != NaN`, and
-# `isNaN(undefined) == true`, so we make sure it's a number first.
-_.isNaN = (obj) -> _.isNumber(obj) and window.isNaN(obj)
-
-
-# Is a given value equal to null?
-_.isNull = (obj) -> obj is null
-
-
-# Is a given variable undefined?
-_.isUndefined = (obj) -> typeof obj is 'undefined'
-
-
-# Utility Functions
-# -----------------
-
-# Run Underscore.js in noConflict mode, returning the `_` variable to its
-# previous owner. Returns a reference to the Underscore object.
-_.noConflict = ->
- root._ = previousUnderscore
- this
-
-
-# Keep the identity function around for default iterators.
-_.identity = (value) -> value
-
-
-# Run a function `n` times.
-_.times = (n, iterator, context) ->
- iterator.call context, i for i in [0...n]
-
-
-# Break out of the middle of an iteration.
-_.breakLoop = -> throw breaker
-
-
-# Add your own custom functions to the Underscore object, ensuring that
-# they're correctly added to the OOP wrapper as well.
-_.mixin = (obj) ->
- for name in _.functions(obj)
- addToWrapper name, _[name] = obj[name]
-
-
-# Generate a unique integer id (unique within the entire client session).
-# Useful for temporary DOM ids.
-idCounter = 0
-_.uniqueId = (prefix) ->
- (prefix or '') + idCounter++
-
-
-# By default, Underscore uses **ERB**-style template delimiters, change the
-# following template settings to use alternative delimiters.
-_.templateSettings = {
- start: '<%'
- end: '%>'
- interpolate: /<%=(.+?)%>/g
-}
-
-
-# JavaScript templating a-la **ERB**, pilfered from John Resig's
-# *Secrets of the JavaScript Ninja*, page 83.
-# Single-quote fix from Rick Strahl.
-# With alterations for arbitrary delimiters, and to preserve whitespace.
-_.template = (str, data) ->
- c = _.templateSettings
- endMatch = new RegExp("'(?=[^"+c.end.substr(0, 1)+"]*"+escapeRegExp(c.end)+")","g")
- fn = new Function 'obj',
- 'var p=[],print=function(){p.push.apply(p,arguments);};' +
- 'with(obj||{}){p.push(\'' +
- str.replace(/\r/g, '\\r')
- .replace(/\n/g, '\\n')
- .replace(/\t/g, '\\t')
- .replace(endMatch,"✄")
- .split("'").join("\\'")
- .split("✄").join("'")
- .replace(c.interpolate, "',$1,'")
- .split(c.start).join("');")
- .split(c.end).join("p.push('") +
- "');}return p.join('');"
- if data then fn(data) else fn
-
-
-# Aliases
-# -------
-
-_.forEach = _.each
-_.foldl = _.inject = _.reduce
-_.foldr = _.reduceRight
-_.select = _.filter
-_.all = _.every
-_.any = _.some
-_.contains = _.include
-_.head = _.first
-_.tail = _.rest
-_.methods = _.functions
-
-
-# Setup the OOP Wrapper
-# ---------------------
-
-# If Underscore is called as a function, it returns a wrapped object that
-# can be used OO-style. This wrapper holds altered versions of all the
-# underscore functions. Wrapped objects may be chained.
-wrapper = (obj) ->
- this._wrapped = obj
- this
-
-
-# Helper function to continue chaining intermediate results.
-result = (obj, chain) ->
- if chain then _(obj).chain() else obj
-
-
-# A method to easily add functions to the OOP wrapper.
-addToWrapper = (name, func) ->
- wrapper.prototype[name] = ->
- args = _.toArray arguments
- unshift.call args, this._wrapped
- result func.apply(_, args), this._chain
-
-
-# Add all ofthe Underscore functions to the wrapper object.
-_.mixin _
-
-
-# Add all mutator Array functions to the wrapper.
-_.each ['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], (name) ->
- method = Array.prototype[name]
- wrapper.prototype[name] = ->
- method.apply(this._wrapped, arguments)
- result(this._wrapped, this._chain)
-
-
-# Add all accessor Array functions to the wrapper.
-_.each ['concat', 'join', 'slice'], (name) ->
- method = Array.prototype[name]
- wrapper.prototype[name] = ->
- result(method.apply(this._wrapped, arguments), this._chain)
-
-
-# Start chaining a wrapped Underscore object.
-wrapper::chain = ->
- this._chain = true
- this
-
-
-# Extracts the result from a wrapped and chained object.
-wrapper::value = -> this._wrapped
diff --git a/examples/web_server.coffee b/examples/web_server.coffee
deleted file mode 100644
index a7aec1b693..0000000000
--- a/examples/web_server.coffee
+++ /dev/null
@@ -1,12 +0,0 @@
-# Contributed by Jason Huggins
-
-http = require 'http'
-
-server = http.createServer (req, res) ->
- res.writeHeader 200, 'Content-Type': 'text/plain'
- res.write 'Hello, World!'
- res.end()
-
-server.listen PORT = 3000
-
-console.log "Server running at http://localhost:#{PORT}/"