Skip to content

Conversation

@i786m
Copy link

@i786m i786m commented Oct 23, 2025

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

Changelist

I have implemented tests, and used tdd to implement the functions set out in the coursework.

@i786m i786m added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 23, 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 26, 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 @i786m! Kudos on writing clean and readable functions! You did a good job with the unit tests as well. However, unit tests are designed to catch bugs from unexpected usage, which is why it's important to pass different types of parameters and test various scenarios. Please make your test cases more thorough to ensure your functions handle edge cases properly.

// And a character char that does not exist within the case-sensitive str,
// 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 if no 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.

These unit tests are good but they are a bit slim. Can you think of corner and edge cases that your function might encounter? What if, for example, other data types or not all parameters are passed? Thinking about these scenarios will make your function more robust and your tests more thorough.

Choose a reason for hiding this comment

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

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

test("should return '2nd' 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.

Same as my previous comment. What if someone passes "3", undefined, or another unexpected value to your function? I understand your assumptions, but users of your functions (both internal within your team and external if you build some sort of API) can pass values you didn't safeguard against, which can break your function.

Choose a reason for hiding this comment

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

💯

@@ -21,12 +21,30 @@ test("should repeat the string count times", () => {
// 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 original string if 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.

Same here, the test cases are quite limited. If I call your function with something like repeat("hello", "3") or repeat("hello", null), it will work because of javascript's type coercion, but is that the behavior you want? Writing more test cases with different input types will help you catch any behavior that you didn't intentionally design into your function.

@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 26, 2025
@i786m i786m 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 Oct 29, 2025
@i786m i786m requested a review from jennethydyrova October 29, 2025 09:44
@i786m
Copy link
Author

i786m commented Oct 29, 2025

I have amended the code & tests based on the comments made , pleases let me know if this is sufficient.

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 @i786m! Very good job. There are two things I would like you to do before completing this PR.

  1. Remove console logs.
  2. Decide between throwing error and returning error string in repeat fn.

Rest of my comments are optional, just food for thought 🙂

if (stringOfCharacters.length === 0) {
return 0;
}
console.log(Array.from(stringOfCharacters));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please remove this console log? This helps to keep PR clean.

Copy link
Author

Choose a reason for hiding this comment

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

I have removed console log, will ensure future PRs are free from debugging logs

Comment on lines 5 to 13
if (typeof num !== "number" || isNaN(num)) {
throw new Error("Input must be a number");
}
if (!Number.isFinite(num)){
throw new Error("Input must be a finite number");
}
if (!Number.isInteger(num) || num < 0) {
throw new Error("Input must be a non-negative integer");
}
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 validation but I think this could be simplified because at the end your input should be a Non-negative integer. For example, Number.isFinite() and isNan() have some overlap, can you check in the MDN docs?

I am leaving this as an optional comment, no action needs to be taken to complete this PR but I would like you think if this could be written simpler. You do not need to throw different error for each small case, you can have more general error for anything that is negative non-integer.

Copy link
Author

Choose a reason for hiding this comment

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

changed code taking overlap in consideration

Comment on lines 2 to 10
if ( arguments.length !== 2) {
return "Function requires exactly 2 arguments";
}
if (typeof str !== "string") {
return "First argument must be a string";
}
if (!Number.isInteger(count) || count < 0) {
return "Second argument must be a non-negative integer";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I see you extensively use throw Error in other functions, is there a reason you want to use just return here?

Small point, no action required to complete this PR but you could improve your error messages to be something like throw Error("Second argument must be a non-negative integer, received: ${count} (${typeof count})") (same for str). It would be a bit easier to debug.

Copy link
Author

Choose a reason for hiding this comment

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

changed returns to throw errors to match the rest in this sprint

@jennethydyrova jennethydyrova added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 29, 2025
@i786m i786m 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 1, 2025
@i786m i786m requested a review from jennethydyrova November 1, 2025 12:53
Copy link

@wheresdiasd wheresdiasd left a comment

Choose a reason for hiding this comment

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

It looks good overall, @jennethydyrova comments must be addressed IMO.

My comments are only suggestions to improve the code synthax.

@@ -1,5 +1,22 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
if (arguments.length !== 2) {

Choose a reason for hiding this comment

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

That looks good, but can we be more specific about which arguments we are expecting? Using " arguments" works, but in my experience is not very common.

if (findCharacter.length !== 1) {
throw new Error("Character to find must be a single character.");
}
if (stringOfCharacters.length === 0) {

Choose a reason for hiding this comment

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

Would that be the same as
(!stringOfCharacters.length) ?

if (typeof stringOfCharacters !== 'string'){
throw new Error("First argument must be a string.");
}
if (typeof findCharacter !== "string") {

Choose a reason for hiding this comment

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

Can we wrap up this condition and the condition above into a single condition ?

if (stringOfCharacters.length === 0) {
return 0;
}
return Array.from(stringOfCharacters).filter(char => char === findCharacter).length;

Choose a reason for hiding this comment

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

Could we use spread operator here ? [...stringOfCharacters] ?

// And a character char that does not exist within the case-sensitive str,
// 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 if no occurrences of a character", () => {

Choose a reason for hiding this comment

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

@@ -1,5 +1,39 @@
function getOrdinalNumber(num) {
return "1st";
if (arguments.length !== 1) {

Choose a reason for hiding this comment

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

Again, can we be more specific about which arguments we are referring to?

if (!isFinite(num)) {
throw new Error("Input must be a finite number");
}
if (!Number.isInteger(num) || num < 0) {

Choose a reason for hiding this comment

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

Can we wrap all these conditions in one statement ?

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

test("should return '2nd' for 2", () => {

Choose a reason for hiding this comment

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

💯

function repeat() {
return "hellohellohello";
function repeat(str, count) {
if ( arguments.length !== 2) {

Choose a reason for hiding this comment

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

Same about the args here, could we be more specific ?

Copy link

@wheresdiasd wheresdiasd left a comment

Choose a reason for hiding this comment

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

The PR LGTM as you've addressed @jennethydyrova changes, however, I left suggestions to improve code standards, please let me know if you want to discuss any item, we can book a call/pair programming to do it so.

Thanks.

@wheresdiasd wheresdiasd added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 18, 2025
@wheresdiasd wheresdiasd added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 18, 2025
@wheresdiasd
Copy link

Could you please solve conflicts on your branch before I mark it as completed ?

@wheresdiasd wheresdiasd added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Complete Volunteer to add when work is complete and all review comments have been addressed. labels Nov 18, 2025
@i786m i786m 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 18, 2025
@i786m i786m requested a review from wheresdiasd November 18, 2025 16:38

test('should have the correct amount of arguments', () => {
expect(() => repeatStr('hello')).toThrow(new Error("Function requires exactly two arguments: a string and a count. Received 1 arguments"));
expect(() => repeatStr("hello", 3, 3)).toThrow(new Error("Function requires exactly two arguments: a string and a count. Received 3 arguments"));

Choose a reason for hiding this comment

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

We don't need to check if the function receives more than 2 arguments.

We need to check whether the arguments are expected or not.

In this case, you have 2 arguments, and your logic works fine. But that wouldn't be accepted in real use cases.

Ideally, you would first check if the function receives both str and count before proceeding to any other steps, and that would be enough.

In the real world, functions can indeed receive more parameters than they expect, but they don't do anything with these parameters.

Copy link

@wheresdiasd wheresdiasd left a comment

Choose a reason for hiding this comment

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

The logic works, but adding a check to see if the function receives more arguments is unrealistic.

@wheresdiasd wheresdiasd added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 18, 2025
@i786m i786m 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 18, 2025
@i786m i786m requested a review from wheresdiasd November 18, 2025 17:55
@i786m
Copy link
Author

i786m commented Nov 18, 2025

Removed the test for more than 2 arguments as you've pointed out in your previous comment and I've taken your comments on board

@wheresdiasd wheresdiasd 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 18, 2025
Copy link

@wheresdiasd wheresdiasd left a comment

Choose a reason for hiding this comment

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

The PR looks good, although I would still avoid the checking arguments.length whenever possible.

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.

3 participants