-
-
Notifications
You must be signed in to change notification settings - Fork 285
London | 25-ITP-Sep | Payman Issa Baiglu | sprint 3 | 2-practice-tdd #883
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
Changes from all commits
92afa66
9e894a7
ded405e
a124398
e7d7fff
fbacf4a
3585be7
bbc996c
5ee3f6b
354b5ac
fdc1b1a
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,12 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| } | ||
| let count = 0; | ||
| for (let i = 0; i < stringOfCharacters.length; i++) { | ||
| if (stringOfCharacters[i] === findCharacter) { | ||
| count++; | ||
| } | ||
| } | ||
| return count; | ||
| } | ||
| console.log(countChar("hello world!", "l")); | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,12 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const suffixes = ["th", "st", "nd", "rd"]; | ||
| const lastTwoDigits = num % 100; | ||
|
|
||
| if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { | ||
| return num + "th"; | ||
| } | ||
| const suffix = suffixes[(lastTwoDigits % 10)] || "th"; | ||
| return num + suffix; | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,19 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| function repeat(str , count) { | ||
| if (count < 0) { | ||
| throw new Error("Count must be a non-negative integer"); | ||
| } | ||
|
Comment on lines
2
to
4
Contributor
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. How would the caller distinguish the result of the following two function calls?
Both function calls return the same value.
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, I see your point. I changed it so it throw error. |
||
| if (count === 0) { | ||
| return ""; | ||
| } | ||
|
|
||
| let result = ""; | ||
| for (let i = 0; i < count; i++) { | ||
| result += str; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| console.log(repeat("hello", 2)); | ||
|
|
||
|
|
||
| module.exports = repeat; | ||
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.
All the test categories now cover all numbers, but within this category, the samples being used are not very comprehensive. Can you think of what numbers you could have also tested?