From af216f8790892fea572fc702c3bf96d5dbc7cfce Mon Sep 17 00:00:00 2001 From: tousledsmile Date: Thu, 26 Apr 2018 18:57:45 +0200 Subject: [PATCH 1/5] problem1 passed --- tests/problem1.test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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); From 40c2e7e4fd8393100321273870c984ac04bcdf33 Mon Sep 17 00:00:00 2001 From: tousledsmile Date: Thu, 26 Apr 2018 19:07:01 +0200 Subject: [PATCH 2/5] problem2 passed --- tests/problem2.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) 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); From 61538bf84b2486574a441e49c8e962acdb1b3cba Mon Sep 17 00:00:00 2001 From: tousledsmile Date: Thu, 26 Apr 2018 19:36:30 +0200 Subject: [PATCH 3/5] problem3 passed --- tests/problem3.test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/problem3.test.js b/tests/problem3.test.js index 3ee3b3c..5970acc 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)); + } else { + return func(argument); + } + } +} + describe('problem3 - curry', () => { it("returns the same func if it doesn't require any parameters", () => { const func = () => 'apple'; From d9492b1a7b7674f1c1cb4219a1df0718e5b7960b Mon Sep 17 00:00:00 2001 From: tousledsmile Date: Thu, 26 Apr 2018 19:55:49 +0200 Subject: [PATCH 4/5] refactor --- tests/problem3.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/problem3.test.js b/tests/problem3.test.js index 5970acc..77940e4 100644 --- a/tests/problem3.test.js +++ b/tests/problem3.test.js @@ -36,9 +36,9 @@ function curry(func) { return function (argument) { if (argumentsLength > 1) { return curry(func.bind(null, argument)); - } else { - return func(argument); } + + return func(argument); } } From 9ba2e508ca6b168868e36f44c7052d69ab4bc9c2 Mon Sep 17 00:00:00 2001 From: tousledsmile Date: Thu, 26 Apr 2018 20:22:10 +0200 Subject: [PATCH 5/5] problem5 passed --- tests/problem5.test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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);