Skip to content

Instantly share code, notes, and snippets.

@bpinedah
bpinedah / declarative-not-curried.js
Created December 10, 2018 06:50
Currying article
function getResult(a, b, c) {
return (a + b) * c
}
@bpinedah
bpinedah / declarative.js
Created December 10, 2018 06:46
Currying article
const getResult = function(a, b) {
return function(c) {
return (a + b) * c;
}
}
getResult(2, 3)(2);
@bpinedah
bpinedah / arrow-curried.js
Created December 10, 2018 06:41
Currying article
const getResult = (a, b) => c => (a + b) * c;
getResult(2, 3)(2); //10
@bpinedah
bpinedah / curry-detailed.js
Created December 10, 2018 06:24
Currying article
const getResult = function(a, b) {
return function(c) {
return (a + b) * c;
}
}
const sum = getResult(2, 3);
sum(2); // 10
sum(5); // 25
@bpinedah
bpinedah / curry.js
Created December 10, 2018 06:13
Currying article
const getResult = function(a, b) {
return function(c) {
return (a + b) * c;
}
}
getResult(2, 3)(2); //10
@bpinedah
bpinedah / not-curry.js
Created December 10, 2018 06:07
Currying article
function getResult(a, b, c) {
return (a + b) * c;
}
getResult(2, 3, 2); // 10
@bpinedah
bpinedah / curry-composition.js
Last active December 8, 2018 03:43
Composition examples
// Data example
const items = [{name: 'Bruce' }, {name: 'Fabs'}, {name: 'Bruce'}, {name: 'Gaby'}];
/**
* @description Filter by one where condition
* @param w Where condition function
* @returns {Function} filter function
*/
const filter = w => a => a.filter(w);
@bpinedah
bpinedah / instanceof-example.js
Created October 30, 2018 22:25
Understand js series
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
function Tesla() {
this.autodrive = true;
}
Car.prototype = new Tesla();
@bpinedah
bpinedah / tdz-example.js
Created October 30, 2018 21:44
Understand js series
function go(n) {
// n here is defined!
console.log(n); // Object {a: [1,2,3]}
for (let n of n.a) { // ReferenceError
console.log(n);
}
}
go({a: [1, 2, 3]});
@bpinedah
bpinedah / typeof-tdz.js
Created October 30, 2018 21:35
Understand js series
typeof undeclaredVariable;
typeof newLetVariable; // ReferenceError
typeof newConstVariable; // ReferenceError
typeof newClass; // ReferenceError
let newLetVariable;
const newConstVariable = 'hello';
class newClass{};