Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/problem1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions tests/problem2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions tests/problem3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
22 changes: 22 additions & 0 deletions tests/problem5.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down