Created
May 18, 2015 00:22
-
-
Save wavebeem/8e331825f1ad276e7ee5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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