Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
describe("Part 1", function () {
describe("add", function() {
it("calculates that 3 + 4 = 7", function () {
expect(add(3, 4)).toBe(7);
});
});
describe("mul", function() {
it("calculates that 3 * 4 = 12", function () {
expect(mul(3, 4)).toBe(12);
});
});
describe("identityf", function () {
it("creates a function that returns its argument", function () {
var idf3 = identityf(3);
expect(idf3()).toBe(3);
});
});
describe("addf", function () {
it("adds two consecutive calls arguments", function () {
expect(addf(3)(4)).toBe(7);
});
});
describe("applyf", function () {
it("applyf takes a function and returns it so it can be applied to two consec args", function () {
expect(applyf(add)(3)(4)).toBe(7);
expect(applyf(mul)(5)(6)).toBe(30);
});
});
describe("curry", function () {
it("curries add with 3", function () {
var add3 = curry(add, 3);
expect(add3(4)).toBe(7);
});
});
describe("show three ways to implement inc function", function () {
it("curry 1", function () {
var inc = curry(add, 1);
expect(inc(4)).toBe(5);
expect(inc(inc(4))).toBe(6);
});
it("addf", function () {
var inc = addf(1);
expect(inc(4)).toBe(5);
expect(inc(inc(4))).toBe(6);
});
it("applyf", function () {
var inc = applyf(add)(1);
expect(inc(4)).toBe(5);
expect(inc(inc(4))).toBe(6);
});
});
describe("twice converts a binary to a unary that uses the same arg twice", function() {
it("should double", function() {
var doubl = twice(add);
expect(doubl(2)).toBe(4);
expect(doubl(123)).toBe(246);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.