Repository navigation
London | 26-ITP-Sep | Mahir Shah | Sprint 2 | Practice TDD #1696
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 all commits
f136a71
bc6f87b
48dddd2
c7cd558
5f56a02
c1ea0a7
966373a
6ad7b43
ea11468
afa99b8
ffc8cc5
19b6fd7
280fe5c
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,3 +1,9 @@ | ||
| export function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let count = 0; | ||
| for (let i = 0; i < stringOfCharacters.length; i++) { | ||
| if (stringOfCharacters[i] === findCharacter) { | ||
| count += 1; | ||
| } | ||
| } | ||
| return count; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,19 @@ | ||
| export function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const numString = num.toString(); | ||
| const lastDigit = numString.slice(-1); | ||
| const last2Digit = numString.slice(-2); | ||
|
|
||
| if (lastDigit === "1" && last2Digit !== "11") { | ||
| return numString + "st"; | ||
| } | ||
|
|
||
| if (lastDigit === "2" && last2Digit !== "12") { | ||
| return numString + "nd"; | ||
| } | ||
|
|
||
| if (lastDigit === "3" && last2Digit !== "13") { | ||
| return numString + "rd"; | ||
| } | ||
|
|
||
| return numString + "th"; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,14 @@ | ||
| export function repeatStr() { | ||
| export function repeatStr(str, count) { | ||
| // Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat). | ||
| // The goal is to re-implement that function, not to use it. | ||
| return "hellohellohello"; | ||
| if (count < 0) { | ||
| throw new Error("Error - invalid count number"); | ||
| } | ||
|
|
||
| let repeatedStr = ""; | ||
| for (let i = count; i > 0; i--) { | ||
| repeatedStr += str; | ||
| } | ||
|
|
||
| return repeatedStr; | ||
| } |
|
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. Your test cases are correct. Just for you to think a little bit more, besides const
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 added tests for empty strings 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. Well done. |
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.
Good coverage of test cases.