Skip to content

Conversation

@shaghayeghfar
Copy link

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

@shaghayeghfar shaghayeghfar added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 28, 2025
@jennethydyrova jennethydyrova added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 28, 2025
Copy link
Contributor

@jennethydyrova jennethydyrova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shaghayeghfar ! Good start on this PR, I left some comments to address

// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.

test("should return 0 when the character does not exist in the string", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test suite is very slim, can you think of more test cases? You should try to cover as many scenarios as possible to test whether your function behaves right if something expected or unexpected passed to your function.

@@ -1,5 +1,8 @@
function getOrdinalNumber(num) {
return "1st";
function getOrdinalNumber(number) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this function is not passing the acceptance criteria. What if I pass, for example, 23 to it?

expect(getOrdinalNumber(1)).toEqual("1st");
});

// Case 2: Identify the ordinal number for 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good illustration why you need to write more versatile unit tests. Before fixing your function, add more unit tests (for different numbers) and see if they pass. You will see that they do not and this is a good sign that your function implementation is incorrect.

// 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.

test("should return the original string when count is 1", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These unit tests are correct but they are a bit limited. What if I pass undefined as str and count 2? What if I pass empty string? You should try to guard your function against these scenarios and unit tests help to think of different scenarios.

@@ -1,5 +1,11 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
let count = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of for loop!

@jennethydyrova jennethydyrova added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Oct 28, 2025
@shaghayeghfar
Copy link
Author

@jennethydyrova

Dear Jennet,

Thank you very much for reviewing my code. I have made the changes you suggested.

I really appreciate your help, time, and effort.

Best regards,

Copy link
Contributor

@jennethydyrova jennethydyrova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shaghayeghfar! Very nice improvement since last iterations but there are couple of more things you will need to do before we can mark this PR as complete.

expect(count).toEqual(0);
});

test("should return 0 when the character does not exist in the string", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate of the test on L47

expect(count).toEqual(5);
});

test("should count multiple occurrences of a character", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this is a good improvement on the previous iteration. Can you think of corner cases? What if length of stringOfCharacters is shorter than length of findCharacter? What either of them is an empty string or some other data type?


// Case 2: Identify the ordinal number for 2
// When the number is 2,
// Then the function should return "2nd"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the comment for countChar function's tests. If I pass undefined, I think your function will output undefinedth, is this a behaviour you expect? Can you think of other corner cases and how you can guard your function against them?

Comment on lines +2 to +19
if (str === undefined) {
throw new Error("String must be defined");
}
if (str === null || typeof str !== "string") {
throw new Error("String must be a valid string");
}

if (count === undefined || typeof count !== "number") {
throw new Error("Count must be a number");
}

if (count < 0 || !Number.isInteger(count)) {
throw new Error("Count must be a non-negative integer");
}

if (str === "" || count === 0) {
return "";
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is okay but it could be simplified by combining some of these if conditions and/or writing more general if condition that would catch most of the cases. You don't need to do anything, it's just something to think about and perhaps to implement on your spare time.

return "";
}

// 5. Repeat the string count times
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment seems a remnant of the sequence of comments. Can you either add all or remove this?

@shaghayeghfar
Copy link
Author

shaghayeghfar commented Oct 30, 2025

Dear Jennet,

Thank you so much for your feedback. I have made the changes you suggested and truly appreciate all your support and guidance .I am very grateful for it.

Copy link
Contributor

@jennethydyrova jennethydyrova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shaghayeghfar! Very good improvement but there are couple of things I would like you fix before we complete this PR. Also, can you please remove any unrelated files from this PR?

function countChar(stringOfCharacters, findCharacter) {
return 5
if (
typeof stringOfCharacters !== "string" ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If either or both arguments are not strings, does it really make sense to return 0? Think of it this way, you call the countChar(2, 3), what would you expect your function to return? I would suggest you to check this link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error

) {
return 0;
}
if (findCharacter.length !== 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good check! As an extension, what if stringOfCharacters.length is 0 and findCharacter.length is 1? I see you now return just 0 but would it perhaps make more sense to throw an error because there is nothing to search character in?

// When the function is called,
// Then it should return 0 because a multi-character string cannot match a single character position.

test("should return 0 when findCharacter is longer than the input string", () => {
Copy link
Contributor

@jennethydyrova jennethydyrova Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a bit incorrect. This is related to my earlier comment for the countChar function. If str length is shorter than char length, the function should return an error. Returning 0 should be reserved only for the case when character is not found. Otherwise, you function logic becomes convoluted, you wouldn't know if it returned 0 because character is not found or because arguments were invalid. Do you see the problem with it?

function getOrdinalNumber(number) {
// Handle invalid inputs
if (typeof number !== "number" || !Number.isFinite(number)) {
return "Invalid input";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is okay but it would be cleaner to mention what you expect as a valid input.

// Case NaN input :
// When the nymber is NaN ,
// Then the function should return "Invalid input"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test cases, very comprehensive!

@shaghayeghfar
Copy link
Author

Dear Jennet,

Thank you for your feedback! I’ve made all the changes you requested. However, I’m not entirely sure what you meant regarding removing the unrelated files. Could you please provide a bit more guidance on that?

Thanks so much for your help!

@jennethydyrova
Copy link
Contributor

Hi @shaghayeghfar! You have some files that are not related to this pull request, such as package.json and package.lock. You shouldn't commit those files if they are not relevant.

Also, you have some conflicts in your PR. Could you please double check?

Screenshot 2025-11-03 at 13 51 26

@jennethydyrova
Copy link
Contributor

Ah, maybe merge conflicts are due to the changes to the main branch. You can ignore it

@shaghayeghfar shaghayeghfar force-pushed the coursework/sprint-3-practice-tdd1 branch from 2f117e1 to 29a4b36 Compare November 4, 2025 13:33
@shaghayeghfar
Copy link
Author

ear Jennet,

Thank you so much for your help and advice. I have deleted the files as you suggested.
I really appreciate your effort and support.

@shaghayeghfar shaghayeghfar added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 4, 2025
Copy link
Contributor

@jennethydyrova jennethydyrova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shaghayeghfar ! I am marking this PR as complete but consider fixing typos

Comment on lines +18 to +26
//stringOfCharacters shoud not be empty
if (stringOfCharacters.length === 0) {
return "stringOfCharacters can not be empty";
}

//findCharacter should not be empty
if (findCharacter.length === 0) {
return "findCharacter can not be empty";
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be combined.

stringOfCharacters.length !== 0 &&
findCharacter.length > stringOfCharacters.length
) {
return "the stringOfCharacters MUST be lonegr than findingcharacter";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in longer and findingcharacter

@jennethydyrova jennethydyrova added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants