Created
May 15, 2013 21:49
-
-
Save imbcmdth/5587695 to your computer and use it in GitHub Desktop.
Wisp vs Wisp's Idea of JavaScript vs real JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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