-
-
Notifications
You must be signed in to change notification settings - Fork 337
West Midlands | Sept-ITP-25 | Mustaf Asani | Sprint 3 | Coursework/sprint 3 practice tdd #813
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
Changes from 7 commits
c518625
51060d9
1a6131d
83c98dc
752f7ae
f04aba1
d754f5a
af1e37a
fea77f0
eac5a16
aec1685
772fae8
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,7 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| const totalChar = stringOfCharacters.split(findCharacter); | ||
|
|
||
| return totalChar.length - 1; | ||
| } | ||
|
|
||
| module.exports = countChar; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,33 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const lastDigit = num.toString()[num.toString().length - 1]; | ||
|
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. Could consider using the more efficient approach involving the
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. used the % to have less code and less function calls |
||
|
|
||
| if (lastDigit === "1") { | ||
| if (num === 11) { | ||
| return `${num}th`; | ||
| } | ||
|
|
||
| return `${num}st`; | ||
| } else if (lastDigit === "2") { | ||
| if (num.toString().length > 1) { | ||
| const last2Digits = num.toString().slice(-2); | ||
|
|
||
| if (last2Digits === "12") { | ||
| return `${num}th`; | ||
| } | ||
| } | ||
| return `${num}nd`; | ||
| } else if (lastDigit === "3") { | ||
| if (num.toString().length > 1) { | ||
| const last2Digits = num.toString().slice(-2); | ||
|
|
||
| if (last2Digits === "13") { | ||
| return `${num}th`; | ||
| } | ||
| } | ||
| return `${num}rd`; | ||
| } | ||
|
|
||
| return `${num}th`; | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,34 @@ const getOrdinalNumber = require("./get-ordinal-number"); | |
| // When the number is 1, | ||
| // Then the function should return "1st" | ||
|
|
||
| test("should return '1st' for 1", () => { | ||
| test("should append 'st' to numbers with 1 at the end except for those ending with 11", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| expect(getOrdinalNumber(21)).toEqual("21st"); | ||
| expect(getOrdinalNumber(101)).toEqual("101st"); | ||
| expect(getOrdinalNumber(151)).toEqual("151st"); | ||
| expect(getOrdinalNumber(2061)).toEqual("2061st"); | ||
| }); | ||
|
|
||
| test("should append 'nd' to numbers with 2 at the end except for those ending with 12", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| expect(getOrdinalNumber(22)).toEqual("22nd"); | ||
| expect(getOrdinalNumber(342)).toEqual("342nd"); | ||
| expect(getOrdinalNumber(592)).toEqual("592nd"); | ||
| expect(getOrdinalNumber(1972)).toEqual("1972nd"); | ||
| }); | ||
|
|
||
| test("should append 'rd' to numbers with 3 at the end except for those ending with 13", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| expect(getOrdinalNumber(33)).toEqual("33rd"); | ||
| expect(getOrdinalNumber(353)).toEqual("353rd"); | ||
| expect(getOrdinalNumber(93)).toEqual("93rd"); | ||
| expect(getOrdinalNumber(783)).toEqual("783rd"); | ||
| }); | ||
|
|
||
| test("should append 'th' to all other numbers which do not end in 1,2,3,11,12 or 13", () => { | ||
| expect(getOrdinalNumber(10)).toEqual("10th"); | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| expect(getOrdinalNumber(212)).toEqual("212th"); | ||
| expect(getOrdinalNumber(113)).toEqual("113th"); | ||
| expect(getOrdinalNumber(17)).toEqual("17th"); | ||
| }); | ||
|
Comment on lines
+11
to
41
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. These tests are quite comprehensive. If you use this test script to test your implementation, you can discover some bug in your code.
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. added code to catch negative and non-integer values
Comment on lines
+35
to
+41
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. If you add enough samples in this categories, you may discover a bug in your implementation.
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 found a bug, in the code for values ending in 11 i had only covered for 11 not other numbers ending in 11. |
||
Uh oh!
There was an error while loading. Please reload this page.