generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 241
Glasgow | 25-ITP-SEP | Mohammed Abdoon | Sprint 3 | Coursework/2-practice-tdd #746
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
M-Abdoon
wants to merge
13
commits into
CodeYourFuture:main
Choose a base branch
from
M-Abdoon:Sprint-3/2_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.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1e5cad7
count.js and count.test.js completed
M-Abdoon a42937d
get-ordinal-numbers.js completed
M-Abdoon 9600443
repeat.js and repeat.test.js completed
M-Abdoon c0d9240
Updated the funciton so it handels other tests, and added more tests too
M-Abdoon f6314c3
function repeat() should return false when negative number passed
M-Abdoon ad2180d
updated function repeat() and its tests
M-Abdoon 94348cb
is shortened inside the function getOrdinalNumber()
M-Abdoon b46e59d
is shortened inside the function getOrdinalNumber()
M-Abdoon f55b3a2
is shortened inside the function getOrdinalNumber()
M-Abdoon f06c4f9
changed condition rule in function getOrdinalNumber() and added new t…
M-Abdoon 25b1868
test cases recategorising
M-Abdoon 06a987e
test cases recategorising -- styling
M-Abdoon 4b42131
corrected condition rule to include NaN and Infinity numbers
M-Abdoon 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
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,10 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let output = 0; | ||
| for( let i=0; i <= stringOfCharacters.length; i++ ) { | ||
| if(stringOfCharacters[i] === findCharacter) | ||
| output++; | ||
| } | ||
| return output; | ||
| } | ||
|
|
||
| module.exports = countChar; |
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,27 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| if (!Number.isInteger(num) || num <= 0) { | ||
| throw new Error("Input must be a positive integer."); | ||
| } | ||
|
|
||
| const lastTwoDigits = num % 100; | ||
| const lastDigit = num % 10; | ||
|
|
||
| if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { | ||
| return `${num}th`; | ||
| } | ||
|
|
||
| switch (lastDigit) { | ||
| case 1: | ||
| return `${num}st`; | ||
| case 2: | ||
| return `${num}nd`; | ||
| case 3: | ||
| return `${num}rd`; | ||
| default: | ||
| return `${num}th`; | ||
| } | ||
| return num; | ||
| } | ||
|
|
||
| //console.log(getOrdinalNumber(21)); // "1st" | ||
| 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,8 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| function repeat(str, count) { | ||
| if (!Number.isInteger(count) || count < 0) { | ||
| throw new Error("Count must be a valid number"); | ||
| } | ||
| return str.repeat(count); | ||
| } | ||
|
|
||
| module.exports = repeat; |
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.
The function should work for any positive integers.
Can you lookup the rules for representing ordinal numbers?
You should prepare tests in
get-ordinal-number.test.jsfile first before implementinggetOrdinalNumber().For example, we can prepare a test for numbers 2, 22, 132, etc. as
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.
Thank you for the feedback. I set the tests for the function and modified the function getOrdinalNumber() to meet the requirements and to handle all possible cases.