Created
August 29, 2015 07:22
-
-
Save n1k0/34781d63ddf33e1b3a0f to your computer and use it in GitHub Desktop.
nuts.js
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
function add(){var a,v,n,f;a=[].slice.call(arguments),v=a[0]||0;if(a.length){n=a.slice(1).reduce(function(s,x){return s+x},v),f=add.bind(0,n);f.valueOf=function(){return n};return f}return v} | |
function test(a, b) { | |
if (a == b) { | |
console.log('OK'); | |
} else { | |
console.log(a + ' != ' + b); | |
} | |
} | |
test(add(1, 2), 3); | |
test(add(3)(4)(), 7); | |
test(add(3)(4)(5), 12); | |
var three = add(3); | |
var four = add(4); | |
test(three, 3); | |
test(four, 4); | |
test(three(5), 8); | |
test(three(6), 9); | |
test(three(four), 7); | |
test(three(four)(three(four)), 14); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment