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
14 changes: 8 additions & 6 deletions __tests__/kata1.fizzBuzz.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
const { fizzBuzz } = require('../src');
import { fizzBuzz } from '../src/kata1.fizzBuzz';

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we're working in node, the import {} from "" syntax doesn't work. We need to use the require syntax here as we do in all the other tests. This is why our tests for fizzbuzz don't run at all atm with the error TypeError: (0 , _kata.fizzBuzz) is not a function


describe('fizzBuzz', () => {
it('returns Fizz when passed a multiple of 3', () => {

xit('returns Fizz when passed a multiple of 3', () => {
expect(fizzBuzz(3)).toBe('Fizz')
});

it('returns Buzz when passed a multiple of 5', () => {

expect(fizzBuzz(5)).toBe('Buzz')
});

it('returns FizzBuzz when passed a multiple 3 and 5', () => {

expect(fizzBuzz(15)).toBe('FizzBuzz')
expect(fizzBuzz(30)).toBe('FizzBuzz')
expect(fizzBuzz(90)).toBe('FizzBuzz')
});

it('returns the number when it isn\'t a multiple of 3 or 5', () => {
xit('returns the number when it isn\'t a multiple of 3 or 5', () => {

});
});
7 changes: 5 additions & 2 deletions __tests__/kata2.booleanToWord.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const { booleanToWord } = require('../src');
const booleanToWord = require('../src/kata2.booleanToWord');

describe('booleanToWord', () => {
// how do we create specs again???
it('test booleanToWord', () => {
expect(booleanToWord(true)).toBe('Yes');
expect(booleanToWord(false)).toBe('No');
})
});
4 changes: 2 additions & 2 deletions __tests__/kata3.numberToReversedDigits.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { numberToReversedDigits } = require('../src');
const numberToReversedDigits = require('../src/kata3.numberToReversedDigits');

describe('numberToReversedDigits', () => {
it('returns a reversed array of the number\'s digits', () => {

expect(numberToReversedDigits(12345)).toEqual(['5', '4', '3', '2', '1']);
});
});
11 changes: 9 additions & 2 deletions __tests__/kata4.humanCatDogYears.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
const { humanCatDogYears } = require('../src');
const humanCatDogYears = require('../src/kata4.humanCatDogYears');

// Look Ma, no handlebars!!!
describe('humanCatDogYears', () => {
it('returns human, cat and dog years', () => {
expect(humanCatDogYears(1)).toEqual([1, 15, 15]);
expect(humanCatDogYears(2)).toEqual([2, 24, 24]);
expect(humanCatDogYears(3)).toEqual([3, 28, 29]);
expect(humanCatDogYears(4)).toEqual([4, 32, 34]);
})
});
4 changes: 2 additions & 2 deletions __tests__/kata5.reachDestination.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { reachDestination } = require('../src');
const reachDestination = require('../src/kata5.reachDestination');

describe('reachDestination', () => {
it('returns string with estimated time of arrival', () => {

expect(reachDestination(5, 10)).toBe('I should be there in 0.5 hours.');
});
});
11 changes: 9 additions & 2 deletions __tests__/kata6.joinNames.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const { joinNames } = require('../src');
const joinNames = require('../src/kata6.joinNames');

describe('joinNames', () => {
it('returns string of names, seperated by commas and an ampersand', () => {

const data = [{
name: 'Bart'
}, {
name: 'Lisa'
}, {
name: 'Maggie'
}];
expect(joinNames(data)).toEqual('Bart, Lisa & Maggie');

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good choice of names :)

});
});
8 changes: 6 additions & 2 deletions __tests__/kata7.getEmployerRole.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const { getEmployerRole } = require('../src');
const getEmployerRole = require('../src/kata7.getEmployerRole');

describe('getEmployerRole', () => {
const employees = [{

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this test, it would have been perfect to have at least another element in the array, to make sure that our function is actually choosing one employee over another.

name: 'Javid',
role: 'Human Recommended Reading Assistant'
}];
it('returns the employee\'s role in the company', () => {
expect(getEmployerRole('Javid', employees).toEqual('Human Recommended Reading Assistant'))
});
});
6 changes: 5 additions & 1 deletion src/kata1.fizzBuzz.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const fizzBuzz = (number) => {
if (number % 5 === 0) {
return 'Buzz';
}

return 'Fizz';
}

module.exports = fizzBuzz;
export default fizzBuzz;
8 changes: 6 additions & 2 deletions src/kata2.booleanToWord.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const booleanToWord = (boolean) => {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you'd like something some succinct try a ternary operator like return Boolean(boolean) ? 'Yes' : 'No'


if (boolean === true) {
return 'Yes';
} else {
return 'No';
}
}

module.exports = booleanToWord;
module.exports = booleanToWord
2 changes: 1 addition & 1 deletion src/kata3.numberToReversedDigits.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const numberToReversedDigits = (number) => {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, good use of string methods, nicely concatenated too 👌


return number.toString().split('').reverse('');
}

module.exports = numberToReversedDigits;
23 changes: 23 additions & 0 deletions src/kata4.humanCatDogYears.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
const humanCatDogYears = (number) => {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job on this one. Ideally, we should try to make sure our code is well structured (indentation, spacing and variables well named).

let tmp = number;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to assign number to temp as we can use number throughout the algorithm.

let catAge = 0;
let dogAge = 0;

if (tmp === 0) {
return [0, 0, 0];
}

if (tmp > 0) {
catAge += 15;
dogAge += 15;
}

if (tmp > 1) {
catAge += 9;
dogAge += 9;
}

if (tmp > 2) {
catAge += (4 * (tmp-2));
dogAge += (5 * (tmp-2));
}

return [number, catAge, dogAge]
}

module.exports = humanCatDogYears;
4 changes: 2 additions & 2 deletions src/kata5.reachDestination.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const reachDestination = (distance, speed) => {

const reachDestination = (d, s) => {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good and succinct implementation. Ideally, we call our variables more than single vowels, like distance instead of d and speed intead of s.

return `I should be there in ${Math.round((d/s) * 2) / 2} hours.`;
}

module.exports = reachDestination;
3 changes: 2 additions & 1 deletion src/kata6.joinNames.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const joinNames = (namesObj) => {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 A comment on the variable naming, x makes sense in a situation where we're talking about spacial coordinates, but on an array of names not as much. Maybe we can use name instead?


const names = namesObj.map((x) => x.name).join(', ')
return names.substring(0, names.lastIndexOf(',')) + ' &' + names.substring(names.lastIndexOf(',') +1)
}

module.exports = joinNames;
10 changes: 7 additions & 3 deletions src/kata7.getEmployerRole.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const getEmployerRole = (employeeName, employees) => {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're very close in nailing the implementation of this one:

  • first error is employee is not defined and that's because it needs to be declared like for (let employee of employees) 💡 notice the let
  • then our comparison in the if statement: employee is the whole object that includes name and role, so we might want to write it like if (employee.name === employeeName)
  • finally, we want to return the employee role, and we can do that by return employee.role

for (employee of employees) {
if (employee === employeeName) {
return getEmployerRole;
}
}
};

}

module.exports = getEmployerRole
module.exports = getEmployerRole;