const map = (fn, arr) => {
if (!arr.length) return []
const [head, ...tail] = arr
return [fn(head, ...map(fn, tail)]
}map :: (a -> b) -> [a] -> [b]| const assert = require('assert') | |
| const isEqual = (a, b) => { | |
| if (a.length !== b.length) return false | |
| return a.every((aElem, index) => aElem === b[index]) | |
| } | |
| // flip :: (a -> b -> c) -> (b -> a -> c) | |
| const flip = (f) => (a, b) => f(b, a) |
| data List a = | |
| Empty | | |
| Cons a (List a) | |
| deriving ( | |
| Eq, | |
| Ord | |
| ) | |
| -- Type classes are pretyy cool |
| type AssociativeList key value = [(key, value)] | |
| type Name = String | |
| type PhoneNumber = String | |
| type PhoneBook = AssociativeList Name PhoneNumber |
| decrementBy :: (Ord a, Num a) => a -> a -> a | |
| decrementBy n d | |
| | n < d = 0 | |
| | otherwise = n - d | |
| --- 1 `decrementBy` 2 | |
| --- 0 | |
| --- 2 `decrementBy` 1 | |
| --- 1 | |
| --- pi `decrementBy` 1 |
const map = (fn, arr) => {
if (!arr.length) return []
const [head, ...tail] = arr
return [fn(head, ...map(fn, tail)]
}map :: (a -> b) -> [a] -> [b]| Manual Rides - From MMF and Strava and Entered through their EDH Account |
| import { expect } from 'chai' | |
| const head = (arr = []) => arr.slice(0)[0] | |
| const tail = (arr = []) => arr.slice(1) | |
| const last = (arr = []) => arr.slice(0).pop() | |
| const init = (arr = []) => arr.slice(0, arr.length - 1) | |
| const subExpression = (tokens, depth = 0, currentBranch = []) => { | |
| if (tokens.length === 0 || head(tokens) === ')') { | |
| return [currentBranch, tail(tokens)] |
| import { expect } from 'chai' | |
| const head = (arr = []) => arr[0] | |
| const tail = (arr = []) => arr.slice(1) | |
| const last = (arr = []) => arr.slice(0).pop() | |
| const init = (arr = []) => arr.slice(0, arr.length - 1) | |
| const nextInScope = (tokens, depth = 1, closeCount = 0) => { | |
| if (depth === closeCount) { | |
| return tokens |
| // I18n | |
| const translateable = (translations) => (Component) => | |
| (props = { locale: 'default' }) => { | |
| const localTranslations = translations[locale] | |
| return <Component { ...props } { ...localTranslations } /> | |
| } | |
| const Greeter = ({ greeting, name }) => | |
| <p>{ greeting }, { name }</p> |
| 'use strict' | |
| const crypto = require('crypto') | |
| const fs = require('fs') | |
| const mkdirp = require('mkdirp') | |
| const path = require('path') | |
| const recursive = require('recursive-readdir') | |
| const assign = Object.assign | |
| const keys = Object.keys |