Skip to content

Instantly share code, notes, and snippets.

View halan's full-sized avatar
🛹

Halan Pinheiro halan

🛹
View GitHub Profile
@halan
halan / add10.js
Last active February 25, 2017 01:12
const add = (a, b) => a + b;
add.length // 2
const add10 = add.bind(this, 10);
add10.length // 1
console.log(add10(5)); // 15
let accumulator = 0;
for(let index = 0; index < collection.length; index++) {
accumulator = // get current accumulator and collection[index] and do some calculation
}
return accumlator;
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 =>
@halan
halan / sum.js
Created February 18, 2017 22:01
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));
@halan
halan / reduce.js
Last active February 23, 2017 15:16
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 =>
@halan
halan / sumline.js
Last active February 18, 2017 21:52
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;
@halan
halan / sumtotal.js
Last active February 18, 2017 21:26
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;
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');
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' };
@halan
halan / curry.js
Last active November 23, 2016 12:30
Técnicas com curry e composição
const map = transform => arr => {
let transformed = []
for(let i=0; i<=arr.length; i++) {
transformed = [...transformed, transform(arr[i], i)]
}
return transformed
}