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; | |
add.length // 2 | |
const add10 = add.bind(this, 10); | |
add10.length // 1 | |
console.log(add10(5)); // 15 |
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
let accumulator = 0; | |
for(let index = 0; index < collection.length; index++) { | |
accumulator = // get current accumulator and collection[index] and do some calculation | |
} | |
return accumlator; |
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 totalLine = line => | |
line.quantity * line.price; | |
const sum = (a, b) => a + b; | |
const map = fn => xs => xs.map(fn); | |
const reduce = (fn, ini) => xs => xs.reduce(fn, ini) | |
const sumTotal = lines => |
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 totalLine = line => | |
line.quantity * line.price; | |
const sum = (a, b) => a + b; | |
const sumTotal = lines => | |
lines.map(totalLine).reduce(sum, 0); | |
console.log(sumTotal(lineItems)); |
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 lineItems = [ | |
{ name: 'Carmenere', price: 35, quantity: 2 }, | |
{ name: 'Cabernet', price: 50, quantity: 1 }, | |
{ name: 'Merlot', price: 98, quantity: 10 }, | |
]; | |
const totalLine = line => | |
line.quantity * line.price; | |
const sumTotal = lines => |
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 totalLine = line => line.quantity * line.price; | |
const sumTotal = lines => { | |
let total = 0; | |
for(let i = 0; i < lines.length; i++) { | |
total += totalLine(lines[i]) | |
} | |
return total; |
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 lineItems = [ | |
{ name: 'Carmenere', price: 35, quantity: 2 }, | |
{ name: 'Cabernet', price: 50, quantity: 1 }, | |
{ name: 'Merlot', price: 98, quantity: 10 }, | |
]; | |
const sumTotal = lines => { | |
let total = 0; | |
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 { createStore } from 'redux' | |
const Pokemon = { | |
init: (specie) => ({ level: 1, specie }), | |
setSpecie: (prev, specie) => ({ ...prev, specie }), | |
updateLevel: (prev) => ({ ...prev, level: prev.level + 1}) | |
} | |
const eevee = Pokemon.init('Eevee'); |
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 { createStore } from 'redux' | |
const eevee = { especie: 'Eevee', level: 1 }; | |
const eeveelution = (state = eevee, action) => { | |
switch (action.type){ | |
case 'WATER_STONE': | |
return { ...state, specie: 'Vaporeon' }; | |
case 'THUNDER_STONE': | |
return { ...state, specie: 'Jolteon' }; |
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 map = transform => arr => { | |
let transformed = [] | |
for(let i=0; i<=arr.length; i++) { | |
transformed = [...transformed, transform(arr[i], i)] | |
} | |
return transformed | |
} |