-
-
Notifications
You must be signed in to change notification settings - Fork 335
Manchester | 26-ITP-Jan | Mehroz Munir | Sprint 3 | Practice TDD Coursework #1147
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 1 commit
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,8 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| if (findCharacter === "") | ||
| return 0; | ||
| else | ||
| return stringOfCharacters.split(findCharacter).length -1; | ||
|
||
| } | ||
|
|
||
| module.exports = countChar; | ||
| module.exports = countChar; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,17 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| let numberString = String(num); | ||
| lastTwoCharactersNumberString = numberString.slice(-2); | ||
| lastCharacterNumberString = numberString.slice(-1); | ||
| if(lastTwoCharactersNumberString === "11") | ||
|
||
| return num+ "th"; | ||
| else if(lastCharacterNumberString === "1") | ||
| return num+ "st"; | ||
| else if(lastCharacterNumberString === "2") | ||
| return num+"nd"; | ||
| else if(lastCharacterNumberString === "3") | ||
| return num + "rd"; | ||
| else | ||
| return num + "th"; | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
| module.exports = getOrdinalNumber; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,17 @@ | ||
| function repeatStr() { | ||
| return "hellohellohello"; | ||
| function repeatStr(str, count) { | ||
| try{ | ||
|
||
| if(count === 0) | ||
| return ""; | ||
| else if(count === 1) | ||
| return str; | ||
| else if(count < 0) | ||
| throw new Error("an error is thrown"); | ||
| else | ||
| return str.repeat(count); | ||
| } | ||
| catch(e){ | ||
|
||
| return e.message; | ||
| } | ||
| } | ||
|
|
||
| module.exports = repeatStr; | ||
| 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.
good validation checking. is there perhaps another parameter here that could result in the same output?
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.
Yes I think that I can check the length of the findCharacter here and if that is 0 I would return 0;
if (findCharacter.length === 0) return 0;And I think that is a better validation than checking if string is empty. I have replaced this in my code now.
Thanks
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.
While that is true I was actually referring to something else.
Look at the method again and see
is there perhaps another parameter here that could result in the same output?Uh oh!
There was an error while loading. Please reload this page.
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.
oh yes. Actually, if
stringOfCharacters.length === 0, I am expecting the same result. I have added it to my code now.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.
@MehrozMunir 100% yes! defensive coding is always a good idea