Skip to content

Instantly share code, notes, and snippets.

View halan's full-sized avatar
🛹

Halan Pinheiro halan

🛹
View GitHub Profile
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');
@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;
@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 / 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 / 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));
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 =>
let accumulator = 0;
for(let index = 0; index < collection.length; index++) {
accumulator = // get current accumulator and collection[index] and do some calculation
}
return accumlator;
@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
@halan
halan / angular.controller.js
Created March 2, 2017 15:50 — forked from suissa/angular.controller.js
Exemplo de uma função em um controller em ng 1.6
function ListController ( Service, $mdDialog ) {
const vm = this;
vm.list = true;
vm.MODULE_NAME = MODULE_NAME;
vm.PATH = MODULE_NAME.toLowerCase();
const hiddenFields= [
'active'
, 'password'
, 'automaticLogin'
import Html
main = Html.text "Hello World"