-
-
Notifications
You must be signed in to change notification settings - Fork 391
London | 26-ITP-May | Bisrat Tesfay | Sprint 3 | Practice TDD #1510
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
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,11 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let count = 0; | ||
| for (let i = 0; i < stringOfCharacters.length; i++) { | ||
| if (stringOfCharacters[i] === findCharacter) { | ||
| count++; // count = count + 1; | ||
| } | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,24 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const lastDigit = num % 10; | ||
| const lastTwoDigits = num % 100; | ||
|
|
||
| if (!Number.isInteger(num) || num < 1) { | ||
| throw new Error("Input must be a positive integer"); | ||
| } | ||
|
|
||
| if (lastDigit === 1 && lastTwoDigits !== 11) { | ||
| return `${num}st`; | ||
| } | ||
|
|
||
| if (lastDigit === 2 && lastTwoDigits !== 12) { | ||
| return `${num}nd`; | ||
| } | ||
|
|
||
| if (lastDigit === 3 && lastTwoDigits !== 13) { | ||
| return `${num}rd`; | ||
| } | ||
|
|
||
| return `${num}th`; | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; |
|
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 like that you're handling invalid inputs! To make it even clearer, what do you think about moving the error check to the very top.
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. Thank you for the comment, you are absolutely right. I have moved the error check to the top. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,15 @@ | ||
| function repeatStr() { | ||
| // 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"; | ||
| function repeatStr(stringOfCharacters, count) { | ||
| if (count < 0) { | ||
| throw new Error("Invalid input: count must be a non-negative integer"); | ||
| } | ||
|
|
||
| let result = ""; | ||
|
|
||
| for (let i = 0; i < count; i++) { | ||
| result += stringOfCharacters; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| module.exports = repeatStr; |
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.
We can also add some other test cases to make sure that our function behaves as we want in edge cases, for example what happens when the str is empty? or has spaces , or is it case sensitive ( finding 'a' in 'Apple' )
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 was just following the given scenarios but now I have add those cases too.
Thank you