Skip to content

Manchester | 26-ITP-Jan | Mehroz Munir | Sprint 3 | Practice TDD Coursework#1147

Open
MehrozMunir wants to merge 4 commits intoCodeYourFuture:mainfrom
MehrozMunir:coursework/sprint-3-practice-tdd
Open

Manchester | 26-ITP-Jan | Mehroz Munir | Sprint 3 | Practice TDD Coursework#1147
MehrozMunir wants to merge 4 commits intoCodeYourFuture:mainfrom
MehrozMunir:coursework/sprint-3-practice-tdd

Conversation

@MehrozMunir
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

Changelist

Created maximum possible categorical test cases and then corrected the implementation so that all the test cases be passed.

@MehrozMunir MehrozMunir added 📅 Sprint 3 Assigned during Sprint 3 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Structuring-And-Testing-Data The name of the module. labels Mar 3, 2026
@@ -1,5 +1,8 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
if (findCharacter === "")

Choose a reason for hiding this comment

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

good validation checking. is there perhaps another parameter here that could result in the same output?

Copy link
Author

Choose a reason for hiding this comment

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

Yes I think that I can check the length of the findCharacter here and if that is 0 I would return 0;

if (findCharacter.length === 0) return 0;

And I think that is a better validation than checking if string is empty. I have replaced this in my code now.

Thanks

Choose a reason for hiding this comment

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

While that is true I was actually referring to something else.
Look at the method again and see is there perhaps another parameter here that could result in the same output?

Copy link
Author

@MehrozMunir MehrozMunir Mar 16, 2026

Choose a reason for hiding this comment

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

oh yes. Actually, if stringOfCharacters.length === 0, I am expecting the same result. I have added it to my code now.

Choose a reason for hiding this comment

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

@MehrozMunir 100% yes! defensive coding is always a good idea

if (findCharacter === "")
return 0;
else
return stringOfCharacters.split(findCharacter).length -1;

Choose a reason for hiding this comment

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

interesting use of split to solve this question, it works perfectly.
how did you think to use split?

Copy link
Author

Choose a reason for hiding this comment

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

When I was thinking about the solutions how can i count the number of characters in a given string. The first thing came to my mind was the use of some loop to go through each character of string and compare it with the character i am looking for and add 1 to your count.

But, then I realized that I can solve it more efficiently without using loop with the use of split method as through split I can get an array of strings separated by character i am looking for in the separater parameter.

So, if I have five occurences of my character in the string, it will return my an array of size 6 that would be strings separated by that character including the empty strings.

Choose a reason for hiding this comment

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

Very good, nice innovative solution

let numberString = String(num);
lastTwoCharactersNumberString = numberString.slice(-2);
lastCharacterNumberString = numberString.slice(-1);
if(lastTwoCharactersNumberString === "11")

Choose a reason for hiding this comment

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

please check your formatting in this file.
make sure it follows the style guide and its consistent so that its easily readable and maintainable

Copy link
Author

Choose a reason for hiding this comment

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

I am sorry my mistake. I had installed prettier for formatting, but did not enable it in the settings as the default formatter and use it on save. I have done it now. And it looks much better.

Thank you.

function repeatStr() {
return "hellohellohello";
function repeatStr(str, count) {
try{

Choose a reason for hiding this comment

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

please check your formatting in this file.
make sure it follows the style guide and its consistent so that its easily readable and maintainable

else
return str.repeat(count);
}
catch(e){

Choose a reason for hiding this comment

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

why are you wrapping this in a try catch?

Copy link
Author

Choose a reason for hiding this comment

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

I was wrapping it because i was catching the thrown error in the catch block and send the error message string back so that I will be able to compare this string in my test file and would know that the error actually is being thrown.

But, I just have learned about the better way how can I test errors thrown in my test file while I was working on a different part of this module. And for that I don't need try catch block here. I have implement this change in the code.

Thanks.

Choose a reason for hiding this comment

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

Okay awesome.
Yes there are definitely use cases for "try catch" but its generally not good practice to do "try {} catch (Exception e)" as this treats all exceptions equally and will result in the same behaviour regardless of the type/severity of the exception. it is better to be more explicit with errors and know exactly how you are handling each error. More effort but very worth it when you are trying to debug an issue and all you see is "exception was thrown"

Copy link
Author

Choose a reason for hiding this comment

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

Yes, thank you for the advice. I totally agree with that. I have updated the error message now.

Thanks.

@kyle-tightest kyle-tightest 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 Mar 12, 2026
@MehrozMunir MehrozMunir added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 14, 2026
@kyle-tightest kyle-tightest removed the Reviewed Volunteer to add when completing a review with trainee action still to take. label Mar 16, 2026
@kyle-tightest kyle-tightest 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 Mar 17, 2026
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. Module-Structuring-And-Testing-Data The name of the module. 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants