-
-
Notifications
You must be signed in to change notification settings - Fork 396
Manchester | 26-ITP-May | Yee Man Tsang | Sprint 3 | 2-practice-tdd #1507
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 countTime = 0; | ||
| for (let i = 0; i < stringOfCharacters.length; i++) { | ||
| if (stringOfCharacters[i] == findCharacter) {//take each character out from string to compare with the given character. If true, then add one to countTime. | ||
| countTime = countTime + 1; | ||
| } | ||
| } | ||
| return countTime; | ||
| } | ||
|
|
||
| module.exports = countChar; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,22 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| let onesDigit = Number(String(num).slice(-1)); //extract the figure at the tens digit, and convert it into a number. | ||
| let tensDigit; | ||
| if (String(num).length > 1) { | ||
| tensDigit = Number(String(num).slice(-2, -1)); //extract the figure at the tens digit, and convert it into a number. | ||
| } | ||
| if (tensDigit === 1) { | ||
| return num + "th"; | ||
| } else { | ||
| if (onesDigit === 1) { | ||
| return num + "st"; | ||
| } else if (onesDigit === 2) { | ||
| return num + "nd"; | ||
| } else if (onesDigit === 3) { | ||
| return num + "rd"; | ||
| } else { | ||
| return num + "th"; | ||
| } | ||
| } | ||
|
Comment on lines
+4
to
+19
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 is a mostly working solution, but with a lot of nested if statements it can be quite hard to follow the logic of it. A few things to consider:
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. Thanks for guiding me on this problem. I am having some insights for how to make this kind of statement in the future. 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 is so much better Lin! I hope you are happy with this improvement 😄 |
||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,15 @@ | ||
| function repeatStr() { | ||
| 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"; | ||
| let strOutput = ""; | ||
| if (count >= 0){ | ||
| for (let i=0 ; i<count ; i++){ | ||
| strOutput = strOutput + str; | ||
| } | ||
| return strOutput; | ||
| }else{ | ||
| throw new Error("Negative count is not valid"); | ||
| } | ||
| } | ||
|
|
||
| module.exports = repeatStr; |
Uh oh!
There was an error while loading. Please reload this page.