-
Notifications
You must be signed in to change notification settings - Fork 12
Brussels | ITP-2025-1 | Preeti Tyagi | Week 6 | Sprint 3 Coursework/sprint-3-practice-tdd #36
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
preeti-t
wants to merge
6
commits into
HackYourFutureBelgium:main
Choose a base branch
from
preeti-t: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.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b847df1
Update count.js
preeti-t 86b258d
Update count.test.js
preeti-t a057212
Update get-ordinal-number.js
preeti-t 3034678
Update get-ordinal-number.test.js
preeti-t 0b5d62f
Update repeat.js
preeti-t 944ab57
Update repeat.test.js
preeti-t 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,15 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let num = 0; | ||
| if (findCharacter) { | ||
| for (let i = 0; i < stringOfCharacters.length; i++) { | ||
| if (stringOfCharacters[i] === findCharacter) { | ||
| num++; | ||
| } | ||
| } | ||
| return `${findCharacter} appears ${num} time(s).`; | ||
| } else return 0; | ||
| } | ||
|
|
||
| // console.log(countChar("Hello", "l")); | ||
|
|
||
| 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,11 @@ | ||
| function getOrdinalNumber(num) { | ||
| if (num > 1 || num < 1) { | ||
| return "No 1st"; | ||
| } | ||
|
|
||
| return "1st"; | ||
| } | ||
|
|
||
| console.log(getOrdinalNumber(1)); | ||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| const getOrdinalNumber = require("./get-ordinal-number"); | ||
| // In this week's prep, we started implementing getOrdinalNumber | ||
| function getOrdinalNumber(num) { | ||
| const remainder10 = num % 10; | ||
| const remainder100 = num % 100; | ||
|
|
||
| // continue testing and implementing getOrdinalNumber for additional cases | ||
| // Write your tests using Jest - remember to run your tests often for continual feedback | ||
| if (remainder10 === 1 && remainder100 !== 11) { | ||
| return `${num}st`; | ||
| } else if (remainder10 === 2 && remainder100 !== 12) { | ||
| return `${num}nd`; | ||
| } else if (remainder10 === 3 && remainder100 !== 13) { | ||
| return `${num}rd`; | ||
| } else { | ||
| return `${num}th`; | ||
| } | ||
| } | ||
|
|
||
| // Case 1: Identify the ordinal number for 1 | ||
| // When the number is 1, | ||
| // Then the function should return "1st" | ||
|
|
||
| test("should return '1st' for 1", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| function repeat(str, times) { | ||
| return str.repeat(times); | ||
| } | ||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,32 @@ | ||
| // Implement a function repeat | ||
| const repeat = require("./repeat"); | ||
| // Given a target string str and a positive integer count, | ||
| // When the repeat function is called with these inputs, | ||
| // Then it should: | ||
|
|
||
| // case: repeat String: | ||
| // Given a target string str and a positive integer count, | ||
| // When the repeat function is called with these inputs, | ||
| // Then it should repeat the str count times and return a new string containing the repeated str values. | ||
|
|
||
| // case: repeat String | ||
| test("should repeat the string count times", () => { | ||
| const str = "hello"; | ||
| const count = 3; | ||
| const repeatedStr = repeat(str, count); | ||
| expect(repeatedStr).toEqual("hellohellohello"); | ||
| }); | ||
|
|
||
| // case: handle Count of 1: | ||
| // Given a target string str and a count equal to 1, | ||
| // When the repeat function is called with these inputs, | ||
| // Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition. | ||
| // case: handle Count of 1 | ||
| test("should return the original string when count is 1", () => { | ||
| const str = "hello"; | ||
| const count = 1; | ||
| const repeatedStr = repeat(str, count); | ||
| expect(repeatedStr).toEqual("hello"); | ||
| }); | ||
|
|
||
| // case: Handle Count of 0: | ||
| // Given a target string str and a count equal to 0, | ||
| // When the repeat function is called with these inputs, | ||
| // Then it should return an empty string, ensuring that a count of 0 results in an empty output. | ||
| // case: Handle Count of 0 | ||
| test("should return an empty string when count is 0", () => { | ||
| const str = "hello"; | ||
| const count = 0; | ||
| const repeatedStr = repeat(str, count); | ||
| expect(repeatedStr).toEqual(""); | ||
| }); | ||
|
|
||
| // case: Negative Count: | ||
| // Given a target string str and a negative integer count, | ||
| // When the repeat function is called with these inputs, | ||
| // Then it should throw an error or return an appropriate error message, as negative counts are not valid. | ||
| // case: Negative Count | ||
| test("should throw an error when count is negative", () => { | ||
| const str = "hello"; | ||
| const count = -2; | ||
| expect(() => repeat(str, count)).toThrow("Count must be a non-negative integer"); | ||
| }); |
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.
Can you implement this please?