-
Notifications
You must be signed in to change notification settings - Fork 217
Kate diy-kata #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Kate diy-kata #19
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,21 @@ | ||
| const { fizzBuzz } = require('../src'); | ||
| import { fizzBuzz } from '../src/kata1.fizzBuzz'; | ||
|
|
||
| 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', () => { | ||
|
|
||
| }); | ||
| }); | ||
| 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'); | ||
| }) | ||
| }); |
| 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']); | ||
| }); | ||
| }); |
| 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]); | ||
| }) | ||
| }); |
| 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.'); | ||
| }); | ||
| }); |
| 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'); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good choice of names :) |
||
| }); | ||
| }); | ||
| 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 = [{ | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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')) | ||
| }); | ||
| }); | ||
| 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; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| const booleanToWord = (boolean) => { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you'd like something some succinct try a ternary operator like |
||
|
|
||
| if (boolean === true) { | ||
| return 'Yes'; | ||
| } else { | ||
| return 'No'; | ||
| } | ||
| } | ||
|
|
||
| module.exports = booleanToWord; | ||
| module.exports = booleanToWord | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| const numberToReversedDigits = (number) => { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,28 @@ | ||
| const humanCatDogYears = (number) => { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to assign |
||
| 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; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| const reachDestination = (distance, speed) => { | ||
|
|
||
| const reachDestination = (d, s) => { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| return `I should be there in ${Math.round((d/s) * 2) / 2} hours.`; | ||
| } | ||
|
|
||
| module.exports = reachDestination; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| const joinNames = (namesObj) => { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👌 A comment on the variable naming, |
||
|
|
||
| const names = namesObj.map((x) => x.name).join(', ') | ||
| return names.substring(0, names.lastIndexOf(',')) + ' &' + names.substring(names.lastIndexOf(',') +1) | ||
| } | ||
|
|
||
| module.exports = joinNames; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| const getEmployerRole = (employeeName, employees) => { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're very close in nailing the implementation of this one:
|
||
| for (employee of employees) { | ||
| if (employee === employeeName) { | ||
| return getEmployerRole; | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| } | ||
|
|
||
| module.exports = getEmployerRole | ||
| module.exports = getEmployerRole; | ||
There was a problem hiding this comment.
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 therequiresyntax here as we do in all the other tests. This is why our tests for fizzbuzz don't run at all atm with the errorTypeError: (0 , _kata.fizzBuzz) is not a function