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
| var getWhiteRabbit = document.getElementById.bind(document, 'white-rabbit'); | |
| var rabbit = getWhiteRabbit(); |
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
| var twinkleBat = twinkle.bind(null, 'bat'); | |
| var twinkleStar = twinkle.bind(null, 'star', 'are'); |
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
| var composeTwo = function(funA, funB) { | |
| return function(x) { | |
| return funA(funB(x)); | |
| } | |
| } | |
| var nohow = function(sentence) { | |
| return sentence + ', nohow!'; | |
| } | |
| var contrariwise = function(sentence) { |
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
| var compose = function() { | |
| var args = arguments; | |
| var start = args.length - 1; | |
| return function() { | |
| var i = start; | |
| var result = args[start].apply(this, arguments); | |
| i = i - 1; | |
| while (i >= 0) { | |
| result = args[i].call(this, result); | |
| i = i - 1; |
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
| var funC = compose(contrariwise, nohow); |
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
| var poem = 'Twas brillig, and the slithy toves\n' + | |
| 'Did gyre and gimble in the wabe;\n' + | |
| 'All mimsy were the borogoves,\n' + | |
| 'And the mome raths outgrabe.'; |
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
| var replace = function(find, replacement, str) { | |
| return str.replace(find, replacement); | |
| } | |
| var wrapWith = function(tag, str) { | |
| return '<' + tag + '>' + str + '</' + tag + '>'; | |
| } | |
| var addBreaks = partial(replace, '\n', '<br/>\n'); | |
| var replaceBrillig = partial(replace, 'brillig', 'four o’clock in the afternoon'); |
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
| var modifyPoem = pipe(replaceBrillig, addBreaks, wrapP, wrapBlockquote); |
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
| var formatName = function(firstname, surname, nickname) { | |
| return firstname + ' “' + nickname + '” ' + surname; | |
| } | |
| var formatNameCurried = curry(formatName); // 🍛 cơm cà-ri | |
| var james = formatNameCurried('James'); // ⚓ fix firstname | |
| console.log(james('Sinclair', 'Mad Hatter')); // 📞 gọi với surname, nickname | |
| //=> James “Mad Hatter” Sinclair |
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
| formatNameCurried('a'); // ‘formatName’ không được gọi, trả về hàm cà-ri | |
| formatNameCurried('a')('b'); // ‘formatName’ không được gọi, trả về hàm cà-ri | |
| formatNameCurried('a', 'b'); // ‘formatName’ không được gọi, trả về hàm cà-ri | |
| formatNameCurried('a')('b')('c'); // ⇨ a “c” b | |
| formatNameCurried('a', 'b', 'c'); // ⇨ a “c” b | |
| formatNameCurried('a', 'b')('c'); // ⇨ a “c” b | |
| formatNameCurried('a')('b', 'c'); // ⇨ a “c” b |