Published
Edited
Jan 16, 2021
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
//+ modulo :: Number -> Number -> Number
modulo = curry((divisor, dividend) => dividend % divisor)
Insert cell
Insert cell
isOdd = modulo(2)
Insert cell
isOdd(6)
Insert cell
isOdd(5)
Insert cell
Insert cell
//+ filter :: (a -> Bool) -> [a] -> [a]
filter = curry((f, xs) => xs.filter(f))
Insert cell
Insert cell
filter(isOdd, [1,2,3,4,5,6,7,8,9])
Insert cell
Insert cell
whatAreTheOdds = filter(isOdd)
Insert cell
Insert cell
whatAreTheOdds([1,2,3,4,5,6,7,8,9])
Insert cell
Insert cell
Insert cell
firstN = curry((n, word) => word.substring(0, n))
Insert cell
Insert cell
first2 = firstN(2)
Insert cell
Insert cell
first2("Hello")
Insert cell
Insert cell
firstTwoLetters = map(first2)
Insert cell
Insert cell
firstTwoLetters(["jim", "kate"])
Insert cell
Insert cell
Insert cell
Insert cell
//+ first :: n -> [a] -> [a]
first = curry((n, array) => array.slice(0, n))
Insert cell
Insert cell
//+ first2 :: [a] -> [a]
firstTwo = first(2)
Insert cell
Insert cell
//+ firstTwoLetters2 :: [[a]] -> [[a]]
firstTwoLetters2 = map(firstTwo) // more concise than: _.map(words, word => firstN(word, 2))
Insert cell
Insert cell
Insert cell
firstTwoLetters2(["jim", "kate"])
Insert cell
Insert cell
map(firstTwo, ["jim", "katy"])
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more