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
| const arrowFunction = (arg1, arg2) => { | |
| const result = arg1 + arg2; | |
| return result; | |
| }; |
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
| lambdaFunction = lambda a, b : a + b |
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
| document.querySelector('#myButton').addEventListner('click', function() { | |
| alert('click happened'); | |
| }); |
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
| const myFirstClassFunction = function(a) { | |
| return function(b) { | |
| return a + b; | |
| }; | |
| }; | |
| myFirstClassFunction(1)(2); // => 3 |
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
| const myFirstClassArrow = a => b => a + b; | |
| myFirstClassArrow(1)(2); // => 3 |
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
| const add = a => b => a + b; | |
| const increaseCounter = counter => add(1)(counter); | |
| increaseCounter(5); // => 6 | |
| const pointFreeIncreaseCounter = add(1); | |
| pointFreeIncreaseCounter(5); // => 6 |
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
| import {trim, upperCaseOf, lengthOf, lastLetterOf, includes, compose} from '@7urtle/lambda'; | |
| const endsWithPunctuation = input => | |
| includes(lastLetterOf(input))('.?,!'); | |
| const replacePunctuationWithExclamation = input => | |
| substr(lengthOf(input) - 1)(0)(input) + '!'; | |
| const addExclamationMark = input => | |
| endsWithPunctuation(input) |
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
| const filterMap = (checker, mapper, list) => | |
| list.reduce( | |
| (acc, current) => checker(current) ? acc.push(mapper(current)) && acc : acc, | |
| [] | |
| ); |
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
| const myList = [1, 2, 3]; | |
| const myChecker = a => a > 1; // filter only numbers larger than 1 | |
| const myMapper = a => a + 1; // make all numbers + 1 | |
| filterMap(myChecker, myMapper, myList); // => [3, 4] |
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
| import {filterMap, includes, upperCaseOf} from '@7urtle/lambda'; | |
| const animals = ['Russian Turtle', 'Greek Turtle', 'House Cat']; | |
| const onlyTurtles = includes('Turtle'); | |
| filterMap(onlyTurtles, upperCaseOf, animals); | |
| // => ['RUSSIAN TURTLE', 'GREEK TURTLE'] | |
| filterMap(onlyTurtles)(upperCaseOf)(animals); // curried | |
| // => ['RUSSIAN TURTLE', 'GREEK TURTLE'] |