Last active
February 5, 2016 06:00
-
-
Save fercreek/903fac8daa98f9d1e57b to your computer and use it in GitHub Desktop.
This file contains 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
"use strict"; | |
// Example 1 | |
let dragon = (name, size, element) => | |
name + ' is a ' + | |
size + ' dragon that breathes ' + | |
element + '!' | |
console.log(dragon('fluffykins', 'tiny', 'lightning')) | |
// Example 2 | |
let dragon = | |
name => | |
size => | |
element => | |
name + ' is a ' + | |
size + ' dragon that breathes ' + | |
element + '!' | |
console.log(dragon('fluffy')('tiny')('lightning')) | |
// Example 3 | |
import _ from 'lodash' | |
let dragon = (name, size, element) => | |
name + ' is a ' + | |
size + ' dragon that breathes ' + | |
element + '!' | |
dragon = _.curry(dragon) | |
let fluffyDragon = dragon('fluffy') | |
let tinyDragon = fluffyDragon('tiny') | |
console.log(tinyDragon('lightning')) | |
// Example 4 | |
let dragons = [ | |
{name: 'Fluffy', element: 'lightning'}, | |
{name: 'noomi', element: 'lightning'}, | |
{name: 'karo', element: 'fire'}, | |
{name: 'doomer', element: 'timewarp'} | |
] | |
let hasElement = (element, obj) => obj.element === element | |
let lightingDragons = | |
dragons.filter(x => hasElement('lightning', x)) | |
console.log(lightingDragons) | |
// Example 5 | |
import _ from 'lodash' | |
let dragons = [ | |
{name: 'Fluffy', element: 'lightning'}, | |
{name: 'noomi', element: 'lightning'}, | |
{name: 'karo', element: 'fire'}, | |
{name: 'doomer', element: 'timewarp'} | |
] | |
let hasElement = _.curry((element, obj) => obj.element === element) | |
let lightingDragons = | |
dragons.filter(hasElement('lightning')) | |
console.log(lightingDragons) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment