Skip to content

Instantly share code, notes, and snippets.

Adam Giese adamgiese

Block or report user

Report or block adamgiese

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@adamgiese
adamgiese / ramda-music.js
Created Oct 3, 2018
Parsing shorthand with Ramda
View ramda-music.js
import { pipe, split, map, match, head, applySpec, join, addIndex, last, add } from 'ramda';
import { Time } from 'tone';
const indexedMap = addIndex(map);
const calcDuration = pipe(split('@'), last);
const parseShorthand = pipe(
split(','),
indexedMap(
applySpec({
View restaurant-list.js
const restaurants = [
{
name: "Dan's Hamburgers",
price: 'cheap',
cuisine: 'burger',
},
{
name: "Austin's Pizza",
price: 'moderate',
cuisine: 'pizza',
@adamgiese
adamgiese / restaurant-chain.js
Created Jul 17, 2018
Declarative Arrays: Chain Restaurant
View restaurant-chain.js
const currentTime = 15; // 3:00 PM
const isOpen = ({hours: {open, close} }) =>
currentTime > open && currentTime < close;
const isFood = ({cuisine}) => cuisine !== 'Coffee';
const toName = ({name}) => name;
const openRestaurants = restaurants
.filter(isOpen)
.filter(isFood)
.map(toName)
@adamgiese
adamgiese / restaurant-reducer.js
Created Jul 17, 2018
Declarative Arrays: Restaurant Reducer
View restaurant-reducer.js
const currentTime = 15; // 3:00 PM
const toOpenRestaurants = (openRestaurants, restaurant) => {
const {
name,
cuisine,
hours: {
open,
close,
}
} = restaurant;
@adamgiese
adamgiese / restaurant.js
Created Jul 17, 2018
Example Restaurant Payload
View restaurant.js
const restaurants = [
{
name: "Pizza Planet",
cuisine: 'Pizza',
hours: {
open: 11,
close: 22,
},
},
{
@adamgiese
adamgiese / callback-parameters.js
Created Jul 17, 2018
Declarative Arrays: Naming Callback Parameters
View callback-parameters.js
const cart = [
{
name: 'Waterloo Sparkling Water',
quantity: 4,
price: 1,
},
{
name: 'High Brew Coffee',
quantity: 2,
price: 2,
@adamgiese
adamgiese / naming-callbacks.js
Created Jul 17, 2018
Declarative Arrays: Naming Callbacks
View naming-callbacks.js
const newEngland = [0,3,6,19,6];
const atlanta = [0,21,7,0,0];
const toScore = (accumulator, value) => accumulator + value;
const atlantaScore = atlanta.reduce((accumulator, value) => accumulator + value);
const newEnglandScore = newEngland.reduce(toScore);
console.log(Math.max(newEnglandScore, atlantaScore));
@adamgiese
adamgiese / divisible-by-three-filter.js
Created Jul 17, 2018
Declarative Arrays: Divisible By 3 Filter
View divisible-by-three-filter.js
const numbers = [1,2,3,4,5,6,7,8,9];
const divisibleByThree = numbers.filter(currentValue => currentValue % 3 === 0);
console.log(divisibleByThree); // [3,6,9];
@adamgiese
adamgiese / square-map.js
Created Jul 17, 2018
Declarative Arrays: Square map
View square-map.js
const numbers = [1,2,3,4,5];
const squares = numbers.map(currentValue => currentValue * currentValue);
console.log(squares); // [1,4,9,16,25];
@adamgiese
adamgiese / sum-reducer.js
Created Jul 17, 2018
Declarative Arrays: Sum reducer
View sum-reducer.js
const numbers = [1,2,3,4,5];
const sum = numbers.reduce(
(accumulator, currentValue) => accumulator + currentValue
);
console.log(sum); // 15
You can’t perform that action at this time.