-
Notifications
You must be signed in to change notification settings - Fork 217
review #25
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?
review #25
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,18 @@ | ||
| const fizzBuzz = number => {}; | ||
| const fizzBuzz = number => { | ||
| return number % 3 === 0 && number % 5 === 0 ? "FizzBuzz" | ||
| : number % 3 === 0 ? "Fizz" | ||
| : number % 5 === 0 ? "Buzz" | ||
| : number; | ||
| }; | ||
|
|
||
|
|
||
|
|
||
| module.exports = fizzBuzz; | ||
|
|
||
|
|
||
| // how to decide whic solution is best: | ||
| // Who is going to use or read the code? | ||
| // Do we want to prioritize readability? | ||
| // For example by putting the checking into separate clearly named functions | ||
| // that make it easy for any reader to know what's going on? | ||
| // or de want to avoid being verbose? | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| const booleanToWord = boolean => {}; | ||
| const booleanToWord = boolean => { | ||
| return boolean ? "Yes" : "No"; | ||
| }; | ||
|
|
||
| module.exports = booleanToWord; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,15 @@ | ||
| const numberToReversedDigits = number => {}; | ||
| const numberToReversedDigits = number => { | ||
| const stringified = String(number); | ||
| const arrayed = stringified.split(""); | ||
| const numberfied = arrayed.map(char => Number(char)); | ||
| return numberfied.reverse(); | ||
| }; | ||
|
|
||
|
|
||
| // less verbose, more chained | ||
|
|
||
| const numberToReversedDigitsChain = number => { | ||
| return String(number).split("").map(char => Number(char)).reverse(); | ||
|
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. I would have done it like this, using chained... |
||
| }; | ||
|
|
||
| module.exports = numberToReversedDigits; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,22 @@ | ||
| const humanCatDogYears = number => {}; | ||
| const calculateAnimalYears = (animal, number) => { | ||
| let factor = animal === "dog" ? 5 : animal === "cat" ? 4 : console.error("animal not recognised"); | ||
|
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. again, don't chain ternaries like this |
||
|
|
||
| if (number === 1) { | ||
| animalYears = 15; | ||
| } else if (number === 2) { | ||
| animalYears = 24; | ||
| } else { | ||
| animalYears = ((number - 2) * factor) + 24; | ||
| } | ||
| return animalYears; | ||
| } | ||
|
|
||
|
|
||
| const humanCatDogYears = number => { | ||
| let catYears = calculateAnimalYears("cat", number) | ||
| let dogYears = calculateAnimalYears("dog", number) | ||
| return [number, catYears, dogYears] | ||
| }; | ||
|
|
||
| module.exports = humanCatDogYears; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,12 @@ | ||
| const reachDestination = (distance, speed) => {}; | ||
| const reachDestination = (distance, speed) => { | ||
| const time = (Math.ceil((distance / speed) * 2) / 2); | ||
| return `I should be there in ${time} hours.` | ||
| }; | ||
|
|
||
| module.exports = reachDestination; | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,17 @@ | ||
| const joinNames = namesObj => {}; | ||
| const joinNames = namesObjArray => { | ||
| const names = namesObjArray.map((person, index) => { | ||
|
|
||
| if (index === namesObjArray.length - 1){ | ||
|
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. nice solution |
||
| return `& ${person.name}` | ||
| } else if (index === namesObjArray.length - 2){ | ||
| return `${person.name}` | ||
| } else { | ||
| return `${person.name},` | ||
| } | ||
| }) | ||
|
|
||
| return names.join(' '); | ||
| }; | ||
|
|
||
| module.exports = joinNames; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,18 @@ | ||
| const getEmployerRole = (employeeName, employees) => {}; | ||
| const getEmployerRole = (employeeName, employees) => { | ||
| return employees.find(emp => emp.name === employeeName).role; | ||
| }; | ||
|
|
||
|
|
||
| module.exports = getEmployerRole; | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| //Function with 2 parameters including a employeeName(string) and an employees(array) | ||
|
|
||
| ///Write a function that takes in an array of objects and a string- which is a name | ||
|
|
||
| ////And we need to return from the function the employee role | ||
|
|
||
| // e.g getEmployerRole('Satti', employees) should return 'Developer' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,27 @@ | ||
| const { fizzBuzz } = require("../src"); | ||
|
|
||
| describe("fizzBuzz", () => { | ||
| test("returns Fizz when passed a multiple of 3", () => {}); | ||
| it("returns Fizz when passed a multiple of 3", () => { | ||
| expect(fizzBuzz(9)).toEqual("Fizz"); | ||
| expect(fizzBuzz(33)).toEqual("Fizz"); | ||
| expect(fizzBuzz(57)).toEqual("Fizz"); | ||
| }); | ||
|
|
||
| test("returns Buzz when passed a multiple of 5", () => {}); | ||
| it("returns Buzz when passed a multiple of 5", () => { | ||
| expect(fizzBuzz(10)).toEqual("Buzz"); | ||
| expect(fizzBuzz(35)).toEqual("Buzz"); | ||
| expect(fizzBuzz(100)).toEqual("Buzz"); | ||
| }); | ||
|
|
||
| test("returns FizzBuzz when passed a multiple 3 and 5", () => {}); | ||
| it("returns FizzBuzz when passed a multiple 3 and 5", () => { | ||
| expect(fizzBuzz(15)).toEqual("FizzBuzz"); | ||
| expect(fizzBuzz(45)).toEqual("FizzBuzz"); | ||
| expect(fizzBuzz(60)).toEqual("FizzBuzz"); | ||
| }); | ||
|
|
||
| test("returns the number when it isn't a multiple of 3 or 5", () => {}); | ||
| it("returns the number when it isn't a multiple of 3 or 5", () => { | ||
| expect(fizzBuzz(4)).toEqual(4); | ||
| expect(fizzBuzz(11)).toEqual(11); | ||
| expect(fizzBuzz(131)).toEqual(131); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,12 @@ | ||
| const { booleanToWord } = require("../src"); | ||
|
|
||
| describe("booleanToWord", () => { | ||
| // how do we create specs again??? | ||
|
|
||
| it((`should return "Yes" when passed true`), () => { | ||
| expect(booleanToWord(true)).toEqual("Yes"); | ||
| }); | ||
|
|
||
| it((`should return "No" when passed false`), () => { | ||
| expect(booleanToWord(false)).toEqual("No"); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| const { numberToReversedDigits } = require("../src"); | ||
|
|
||
| describe("numberToReversedDigits", () => { | ||
| test("returns a reversed array of the number's digits", () => {}); | ||
| const number = 12345; | ||
|
|
||
| it("returns a reversed array of the number's digits", () => { | ||
| expect(numberToReversedDigits(number)).toEqual([5, 4, 3, 2, 1]); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,27 @@ | ||
| const { humanCatDogYears } = require("../src"); | ||
|
|
||
| // Look Ma, no handlebars!!! | ||
| describe("humanCatDogYears", () => { | ||
| it("should return an array with length 3", () => { | ||
| expect(humanCatDogYears(10)).toHaveLength(3) | ||
| }); | ||
|
|
||
| it("should have the passed argument at index 0", () => { | ||
| expect(humanCatDogYears(10)[0]).toBe(10) | ||
| }); | ||
|
|
||
| it("should have the equivalent cat years at index 1", () => { | ||
| expect(humanCatDogYears(10)[1]).toBe(56) | ||
| }); | ||
|
|
||
| it("should have the equivalent dog years at index 2", () => { | ||
| expect(humanCatDogYears(10)[2]).toBe(64) | ||
| }); | ||
|
|
||
| it("should return an array of 3 numbers: human, cat and dog years respectively", () => { | ||
| expect(humanCatDogYears(3)).toEqual([3, 28, 29]) | ||
| expect(humanCatDogYears(6)).toEqual([6, 40, 44]) | ||
| }) | ||
|
|
||
| }); | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,19 @@ | ||
| const { reachDestination } = require("../src"); | ||
|
|
||
| describe("reachDestination", () => { | ||
| test("returns string with estimated time of arrival", () => {}); | ||
| test("returns a string", () => { | ||
| const result = reachDestination(44,10) | ||
| expect(typeof result).toBe("string"); | ||
| }); | ||
|
|
||
| test("returns string with estimated time of arrival", () => { | ||
| expect(reachDestination(44, 10)).toBe('I should be there in 4.5 hours.') | ||
| expect(reachDestination(48, 10)).toBe('I should be there in 5 hours.') | ||
| expect(reachDestination(500, 10)).toBe('I should be there in 50 hours.') | ||
| }); | ||
|
|
||
| }); | ||
|
|
||
|
|
||
|
|
||
|
|
Uh oh!
There was an error while loading. Please reload this page.
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.
I try to avoid chaining ternaries as they get harder to read...
you could have considered
if, orswitchhere.