-
-
Notifications
You must be signed in to change notification settings - Fork 337
Sheffield | ITP-Jan-26 | Hayriye Saricicek | Sprint 3 | practice tdd #1237
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 14 commits
32407f9
3f7a169
2c8e627
3217cc5
7f76795
01e4e00
7604204
ebfb090
e4de3c6
11c8346
e947150
f55e9b5
ebe2c5d
daec403
514a9da
1efb9a9
659e4b2
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,4 +1,4 @@ | ||
| node_modules | ||
| .DS_Store | ||
| .vscode | ||
| **/.DS_Store | ||
| .vscode/ | ||
| **/.DS_Store |
| 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 char of stringOfCharacters) { | ||
| if (char === findCharacter) { | ||
| count++; | ||
| } | ||
| } | ||
|
|
||
| return count; | ||
| } | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,20 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| // Check if input is a number | ||
| if (!Number.isInteger(num) || !Number.isFinite(num) || num <= 0) { | ||
|
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.
|
||
| throw new Error("Input must be a valid number"); | ||
| } | ||
|
|
||
| const lastNum = num % 10; // checks what last number is | ||
| const last2Num = num % 100; // checks what last two numbers are, needed to check for 11 | ||
|
|
||
| if (last2Num >= 11 && last2Num <= 13) { | ||
| return num + "th"; | ||
| } | ||
| if (lastNum === 1) return num + "st"; | ||
| if (lastNum === 2) return num + "nd"; | ||
| if (lastNum === 3) return num + "rd"; | ||
|
|
||
| return num + "th"; | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,39 @@ const getOrdinalNumber = require("./get-ordinal-number"); | |
| // Case 1: Numbers ending with 1 (but not 11) | ||
| // When the number ends with 1, except those ending with 11, | ||
| // Then the function should return a string by appending "st" to the number. | ||
|
|
||
| test("should append 'st' for numbers ending with 1, except those ending with 11", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| expect(getOrdinalNumber(21)).toEqual("21st"); | ||
| expect(getOrdinalNumber(131)).toEqual("131st"); | ||
| }); | ||
|
|
||
| // Case 2: Numbers ending with 2 | ||
| // When the number ends with 2, | ||
| // Then the function should return a string by appending "nd" to the number. | ||
|
|
||
| test("should append 'nd' for numbers ending with 2", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| expect(getOrdinalNumber(32)).toEqual("32nd"); | ||
| expect(getOrdinalNumber(252)).toEqual("252nd"); | ||
| }); | ||
|
|
||
| // Case 3: Numbers ending with 3 | ||
| // When the number ends with 3, | ||
| // Then the function should return a string by appending "rd" to the number. | ||
|
|
||
| test("should append 'rd' for numbers ending with 3", () => { | ||
|
cjyuan marked this conversation as resolved.
Outdated
|
||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| expect(getOrdinalNumber(33)).toEqual("33rd"); | ||
| expect(getOrdinalNumber(133)).toEqual("133rd"); | ||
| }); | ||
|
|
||
| // Case 4: The remaining numbers | ||
| // For numbers that don't end in 1 (not11), 2 and 3 | ||
| // the function should return a string by appending "th" to the number. | ||
|
|
||
| test("should append 'th' if number is 11, 12 or 13 or does not end in 1, 2 or 3",() => { | ||
|
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. This group should also include numbers ending with 11, 12, or 13 (not just that three numbers).
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. Ive changed it. |
||
| expect(getOrdinalNumber(20)).toEqual("20th"); | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| expect(getOrdinalNumber(99)).toEqual("99th"); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,13 @@ | ||
| function repeatStr() { | ||
| return "hellohellohello"; | ||
| function repeatStr(str, count) { | ||
| if (count < 0) { | ||
| throw new Error("Count must be positive"); | ||
| } | ||
|
|
||
| if (count === 0) { | ||
| return " "; | ||
| } | ||
|
|
||
| return str.repeat(count); | ||
| } | ||
|
|
||
| module.exports = repeatStr; |
Uh oh!
There was an error while loading. Please reload this page.