Skip to content

Instantly share code, notes, and snippets.

@imbcmdth
Created May 15, 2013 21:49
Show Gist options
  • Save imbcmdth/5587695 to your computer and use it in GitHub Desktop.
Save imbcmdth/5587695 to your computer and use it in GitHub Desktop.
Wisp vs Wisp's Idea of JavaScript vs real JavaScript
// Wisp:
(fn sum
"Return the sum of all arguments"
{:version "1.0"}
([] 0)
([x] x)
([x y] (+ x y))
([x & more] (more.reduce (fn [x y] (+ x y)) x)))
// What Wisp's developers thinks good JavaScript looks like:
function sum(x, y) {
switch (arguments.length) {
case 0:
return 0;
case 1:
return x;
case 2:
return x + y;
default:
var more = Array.prototype.slice.call(arguments, 1);
return more.reduce(function(x, y) {
return x + y;
}, x);
};
return void(0);
};
// Real JavasScript:
function sum(x, y) {
if(arguments.length < 1) return 0;
return [].slice.call(arguments).reduce(function(x, y) {
return x + y;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment