Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var add = TC()
.Takes([TC.Number, TC.Number])
.Returns(TC.Number)
.By(function(a, b) { return a + b })
var divide = TC()
.Takes([TC.Number, TC.Nonzero])
.Returns(TC.Number)
.By(function(a, b) { return a / b })
var sum = TC()
.Takes([TC.Array(TC.Number)])
.Returns(TC.Number)
.By(function(xs) { return xs.reduce(add, 0) })
var charCount = TC()
.Takes([TC.String])
.Returns(TC.Object(TC.Number))
.By(function(s) {
return s
.split('')
.reduce(function(obj, c) {
obj[c] = 1 + (c in obj ? obj[c] : 0)
return obj
}, Object.create(null))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment