-
-
Notifications
You must be signed in to change notification settings - Fork 352
London | 26-ITP-May | Alex Jamshidi | Sprint 3 | Practice tdd #1319
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,5 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| return stringOfCharacters.split(findCharacter).length - 1; | ||
| } | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,13 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| if (!Number.isInteger(num) || num < 1) {throw new Error("Invalid number");} | ||
|
|
||
| let number = num.toString().slice(-2); | ||
| if (number == 11 || number == 12 || number == 13) {return `${num}th`;} | ||
| if (number.slice(-1) == 1) {return `${num}st`;} | ||
|
Member
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'd extract a variable for that
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. extracted and named lastDigit, code much more readable now |
||
| if (number.slice(-1) == 2) {return `${num}nd`;} | ||
| if (number.slice(-1) == 3) {return `${num}rd`;} | ||
| else return `${num}th`; | ||
|
|
||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| function repeatStr() { | ||
| return "hellohellohello"; | ||
| function repeatStr(str, count) { | ||
| if (count < 0) {throw new Error("Invalid count");} | ||
| let string = ""; | ||
| while (count > 0) { | ||
| string = string + str; | ||
| count--; | ||
| } | ||
| return string; | ||
| } | ||
|
|
||
| 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.
"num" and "number" are very hard to distinguish variables - it's not clear from their names what the differences between them are. Can you think how to improve this?
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.
renamed number to lastTwoDigits to make clearer what is happening