Skip to content

Instantly share code, notes, and snippets.

const arrowFunction = (arg1, arg2) => {
const result = arg1 + arg2;
return result;
};
lambdaFunction = lambda a, b : a + b
document.querySelector('#myButton').addEventListner('click', function() {
alert('click happened');
});
const myFirstClassFunction = function(a) {
return function(b) {
return a + b;
};
};
myFirstClassFunction(1)(2); // => 3
const myFirstClassArrow = a => b => a + b;
myFirstClassArrow(1)(2); // => 3
const add = a => b => a + b;
const increaseCounter = counter => add(1)(counter);
increaseCounter(5); // => 6
const pointFreeIncreaseCounter = add(1);
pointFreeIncreaseCounter(5); // => 6
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)
const filterMap = (checker, mapper, list) =>
list.reduce(
(acc, current) => checker(current) ? acc.push(mapper(current)) && acc : acc,
[]
);
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]
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']