diff --git a/tests/problem1.test.js b/tests/problem1.test.js index fcbe6e4..8a95402 100644 --- a/tests/problem1.test.js +++ b/tests/problem1.test.js @@ -9,6 +9,22 @@ */ +function groupBy(numbersTable, groupFunction) { + return numbersTable.reduce((groupedNumbers, number) => { + const groupName = groupFunction(number) + ''; + + console.log(groupedNumbers) + + if (!groupedNumbers[groupName]) { + groupedNumbers[groupName] = []; + } + + groupedNumbers[groupName].push(number); + + return groupedNumbers; +}, {}); +} + describe('problem1 - groupBy', () => { it('returns an object', () => { expect(groupBy([1, 2, 3], v => v)).toBeInstanceOf(Object); diff --git a/tests/problem2.test.js b/tests/problem2.test.js index abbafab..368c6e2 100644 --- a/tests/problem2.test.js +++ b/tests/problem2.test.js @@ -16,6 +16,14 @@ greetButVeryLoud('John') // HELLO JOHN!!!!!!!!1111one */ +function compose(...functions) { + return function(something) { + return functions.reduce((changedSomething, currentFunction) => { + return currentFunction(changedSomething); + }, something); + } +} + describe('problem2 - compose', () => { function stringToNumber(s) { return parseInt(s); diff --git a/tests/problem3.test.js b/tests/problem3.test.js index 3ee3b3c..77940e4 100644 --- a/tests/problem3.test.js +++ b/tests/problem3.test.js @@ -28,6 +28,20 @@ */ +function curry(func) { + const argumentsLength = func.length; + + if (argumentsLength === 0) return func; + + return function (argument) { + if (argumentsLength > 1) { + return curry(func.bind(null, argument)); + } + + return func(argument); + } +} + describe('problem3 - curry', () => { it("returns the same func if it doesn't require any parameters", () => { const func = () => 'apple'; diff --git a/tests/problem5.test.js b/tests/problem5.test.js index 6ce030d..3de9222 100644 --- a/tests/problem5.test.js +++ b/tests/problem5.test.js @@ -27,6 +27,28 @@ } */ +class Pipe { + constructor(startinValue) { + this.startingValue = startinValue; + } + + static startingWith (value) { + return new Pipe(value); + } + + chain (handler) { + return new Pipe(handler(this.startingValue)); + } + + return () { + return this.startingValue; + } + + finally (handler) { + return handler(this.startingValue); + } +} + describe('problem5 - pipe', () => { it('returns a wrapped value (an object)', () => { expect(Pipe.startingWith(2)).toBeInstanceOf(Pipe);