-
-
Notifications
You must be signed in to change notification settings - Fork 249
Manchester | 25-ITP-September | khalidbih | Sprint 3 | 2-practice-tdd #887
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?
Changes from 8 commits
bd8ab4b
943e88e
b8e36c4
fd6e675
b58f10c
66efc47
9fc5d58
8789a9f
f829a04
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,5 +1,12 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let count = 0; | ||
|
|
||
| for (let i = 0; i < stringOfCharacters.length; i++) { | ||
| if (stringOfCharacters[i] ===findCharacter) { | ||
| count++; | ||
| } | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,21 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| function getOrdinalNumber(num){ | ||
| const lastTwoDigits = num % 100; | ||
| if (lastTwoDigits >= 11 && lastTwoDigits <= 13){ | ||
| return num+ "th"; | ||
| } | ||
|
|
||
| const lastDigit = num %10; | ||
|
|
||
| switch (lastDigit){ | ||
| case 1: | ||
| return num + "st"; | ||
| case 2: | ||
| return num + "nd"; | ||
| case 3: | ||
| return num + "rd"; | ||
| default: | ||
| return num + "th"; | ||
| } | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,48 @@ const getOrdinalNumber = require("./get-ordinal-number"); | |
| test("should return '1st' for 1", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| }); | ||
|
|
||
|
|
||
| test("should return '2nd' for 2", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| }); | ||
|
|
||
|
|
||
| test("should return '3rd' for 3", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| }); | ||
|
|
||
|
|
||
| test("should return '4th' for 4", () => { | ||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
| }); | ||
|
|
||
| test("should return '11th', '12th', '13th' for special cases", () => { | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| expect(getOrdinalNumber(12)).toEqual("12th"); | ||
| expect(getOrdinalNumber(13)).toEqual("13th"); | ||
| expect(getOrdinalNumber(111)).toEqual("111th"); | ||
| expect(getOrdinalNumber(112)).toEqual("112th"); | ||
| expect(getOrdinalNumber(113)).toEqual("113th"); | ||
| }); | ||
|
|
||
| test("should return '21st', '22nd', '23rd'", () => { | ||
| expect(getOrdinalNumber(21)).toEqual("21st"); | ||
| expect(getOrdinalNumber(22)).toEqual("22nd"); | ||
| expect(getOrdinalNumber(23)).toEqual("23rd"); | ||
| expect(getOrdinalNumber(101)).toEqual("101st"); | ||
| expect(getOrdinalNumber(102)).toEqual("102nd"); | ||
| expect(getOrdinalNumber(103)).toEqual("103rd"); | ||
| }); | ||
|
Comment on lines
38
to
46
Contributor
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. The test description does not quite describe the tests being performed. Can you improve it?
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 updated the test description to clearly describe numbers ending in 1, 2, or 3, excluding 11,13. |
||
|
|
||
| test("should return correct 'th' for numbers ending in 4-9 or 0", () => { | ||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
| expect(getOrdinalNumber(5)).toEqual("5th"); | ||
| expect(getOrdinalNumber(10)).toEqual("10th"); | ||
| expect(getOrdinalNumber(24)).toEqual("24th"); | ||
| expect(getOrdinalNumber(100)).toEqual("100th"); | ||
| }); | ||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| function repeatStr() { | ||
| return "hellohellohello"; | ||
| function repeat(str, count) { | ||
| if (count < 0){ | ||
| throw new Error("count cannot be negative"); | ||
| } | ||
|
|
||
| return str.repeat(count); | ||
| } | ||
|
|
||
| module.exports = repeatStr; | ||
| module.exports = repeat; |
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.
“Special cases" isn't a very informative description.
A phrase like "numbers ending in …" would provide more clarity.
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 updated the test description to clearly state that numbers ending in 11, 12, and 13 always use ‘th’.