Created
February 8, 2015 10:10
-
-
Save goatslacker/50a13c11f420b4a5012c to your computer and use it in GitHub Desktop.
This file contains 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
"use strict"; | |
var _tailCall = (function () { | |
function Tail(func, args, context) { | |
this.func = func; | |
this.args = args; | |
this.context = context; | |
} | |
Tail.prototype._isTailDescriptor = true; | |
var isRunning = false; | |
return function (func, args, context) { | |
var result = new Tail(func, args, context); | |
if (!isRunning) { | |
isRunning = true; | |
do { | |
result = result.func.apply(result.context, result.args); | |
} while (result instanceof Tail || result && result._isTailDescriptor); | |
isRunning = false; | |
} return result; | |
}; | |
})(); | |
function format(x) { | |
return _tailCall(x.toUpperCase, [], x); | |
} | |
function makeObj(arr) { | |
return _tailCall(arr.reduce, [function (obj, x) { | |
var upper = format(x); | |
obj[x] = 1; | |
obj[upper] = 2; | |
return obj; | |
}, {}], arr); | |
} | |
var result = makeObj(["yes", "no"]); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment