View 1. intro.md

Create a cond function that takes 2 arguments:

  1. An matrix in the format:
[
  [firstCondition, firstCallback],
  [secondCondition, secondCallback],
  ...
]
View imap-islice.js
/*
* imap lazily maps an interable.
* @param ref Either an iterable or an iterator
* @param fn Map function
*
* It works by always returning a new iterator so that
* you can chain other imaps without looping once more
* over the same array!
*
* Since iterators are returned, to start the real mapping
View validate-posts.js
const validPost = post =>
post.title && post.title.length > 10 && post.content
const posts =
[ {title: 'short'}
, {title: 'fairly long', content: 'Foobar'}
, {title: 'yet another', content: 'fixture'}
]
const validPosts = posts.every(validPost)
View prime-quantifier.js
const range = (start, end) =>
Array.from({length: end - start}, (_, i) => start + i)
const divides = x => y =>
x % y === 0
const prime = n => {
if (n < 2)
return false
if (n === 2)
View has-integer-log.js
const checkAndLog = x => {
console.log('passed by', x)
return Number.isInteger(x)
}
const xs = ['a', 1, 2, 3, 4]
const ys = ['a', 'b', 'c', 'd', 'e']
const xsHasinteger = xs.some(checkAndLog)
// passed by a
View are-all-integers-log.js
const checkAndLog = x => {
console.log('passed by', x)
return Number.isInteger(x)
}
const xs = [1, 2, 3, 4, 5]
const ys = [6, 7, 'a', 9, 10]
const areXsIntegers = xs.every(checkAndLog)
// passed by 1
View has-integer.js
const xs = ['a', 'b', 'c', 'd', 5]
const ys = ['a', 'b', 'c', 'd', 'e']
const xsHasinteger = xs.some(Number.isInteger)
const ysHasinteger = ys.some(Number.isInteger)
console.log(xsHasinteger) // true
console.log(ysHasinteger) // false
View are-all-integers.js
const xs = [1, 2, 3, 4, 5]
const ys = [1, 2, 'a', 4, 5]
const areXsIntegers = xs.every(Number.isInteger)
const areYsIntegers = ys.every(Number.isInteger)
console.log(areXsIntegers) // true
console.log(areYsIntegers) // false
View sane-binary-functions.js
const add = (x, y) => x + y
const sub = (x, y) => x - y
console.log('10 + 3 - 4 =', sub( add(10, 3), 4 ) )
View why-did-u-even-curry.js
const add = x => y => x + y
const sub = x => y => x - y
console.log('10 + 3 - 4 =', sub( add(10)(3) )(4) )