generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 239
NW | 25-ITP-Sep |Ahmad Hmedan | Sprint 3 | Sprint 3 Practice TDD coursework #831
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
Open
AhmadHmedann
wants to merge
8
commits into
CodeYourFuture:main
Choose a base branch
from
AhmadHmedann:coursework/sprint-3-practice-tdd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+143
−8
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a21fb5e
Implement a countChar function and test with jest
AhmadHmedann 1382dc5
Add two test to cover empty string and speciale characters
AhmadHmedann 7172fd2
I have implemented a function called repeat and writen a few differen…
AhmadHmedann 6c50af1
Use built-in .repeat() method instead of manual implementation; add o…
AhmadHmedann 5813df0
Implement getOrdinalNumber function and add comprehensive Jest tests
AhmadHmedann 4369f3a
change the test discription
AhmadHmedann 034d8f8
grouping the tests by behaviour
AhmadHmedann 3be91c2
resolve invalide input to throw a new error insted a return a massage
AhmadHmedann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,18 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let counter = 0; | ||
| let index = stringOfCharacters.indexOf(findCharacter); | ||
| while (index !== -1) { | ||
| counter++; | ||
|
|
||
| index = stringOfCharacters.indexOf(findCharacter, index + 1); | ||
| } | ||
| return counter; | ||
| } | ||
|
|
||
| module.exports = countChar; | ||
| function assertFunction(currentOutput, targetOutput) { | ||
| console.assert( | ||
| currentOutput === targetOutput, | ||
| `expect ${currentOutput} to equal ${targetOutput}` | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,21 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| if (num <= 0) return "Invalid Input"; | ||
| if (num % 100 === 11) return `${num}th`; // check the last two digit if it exception 11, 12 or 13 | ||
| if (num % 100 === 12) return `${num}th`; | ||
| if (num % 100 === 13) return `${num}th`; | ||
| const remainder = num % 10; | ||
| switch (remainder) { | ||
| case 1: | ||
| return `${num}st`; | ||
|
|
||
| case 2: | ||
| return `${num}nd`; | ||
| case 3: | ||
| return `${num}rd`; | ||
|
|
||
| default: | ||
| return `${num}th`; | ||
| } | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,23 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| function repeat(myString, repeatNumber) { | ||
| if (repeatNumber < 0) throw new Error("Repeat count must be a positive number"); | ||
| // if I use this instead return how I can test it with jest?? | ||
| return myString.repeat(repeatNumber); | ||
| } | ||
|
|
||
| module.exports = repeat; | ||
|
|
||
| // Note: | ||
| // When I wrote this code, I didn’t know there was already a built-in method for this. | ||
| // Please review this implementation as well. | ||
| //if (repeatNumber < 0) throw new Error("Repeat count must be a positive number"); if I use this instead return how I can test it with jest?? | ||
|
|
||
| // function repeat(myString, repeatNumber) { | ||
| // if (repeatNumber < 0) return "Invalid Input must be a positive number"; | ||
| // let str = ""; | ||
| // for (let i = 0; i < repeatNumber; i++) { | ||
| // str += myString; | ||
| // } | ||
| // return str; | ||
| // } | ||
|
|
||
| //if (repeatNumber < 0) throw new Error("Repeat count must be a positive number"); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This works too.
While knowing how to use built-in functions can improve productivity and performance, it is equally important to know how to implement such a function without relying on any built-in function.