Last active
February 16, 2020 03:19
-
-
Save greathmaster/68373ac95a612023affc0dad47a30318 to your computer and use it in GitHub Desktop.
Unlocking a secret using curry principles.
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
//Example 1: | |
Function.prototype.secretCurry = function() { | |
let secret = "password" | |
let that = this; | |
return function inner(guess) { | |
if(guess == secret) { | |
that(); | |
} | |
return inner; | |
} | |
} | |
function log() { | |
console.log("You unlocked the secret!") | |
} | |
let f = log.secretCurry(); | |
f("test123")("abc")("password") | |
//Example 2: | |
function curryingExample(str) { | |
let curryStr = "" | |
curryStr += str; | |
return function curryReturn(str2) { | |
if(str2 === undefined) { | |
return curryStr; | |
} | |
else { | |
curryStr += str2; | |
return curryReturn | |
} | |
} | |
} | |
console.log(curryingExample("My ")("name ")("is ")("Snoopy!")()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment