Skip to content

Manchester | 26-ITP-May | Yee Man Tsang | Sprint 3 | 2-practice-tdd#1507

Open
lintsang wants to merge 1 commit into
CodeYourFuture:mainfrom
lintsang:2-practice-tdd
Open

Manchester | 26-ITP-May | Yee Man Tsang | Sprint 3 | 2-practice-tdd#1507
lintsang wants to merge 1 commit into
CodeYourFuture:mainfrom
lintsang:2-practice-tdd

Conversation

@lintsang

Copy link
Copy Markdown

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

Finished all exercises in 2-practice-tdd folder

@Liam310 Liam310 added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Jul 14, 2026
@Liam310

Liam310 commented Jul 14, 2026

Copy link
Copy Markdown

Don't forget to add the Needs review label to your coursework Lin otherwise it might get missed by reviewers!

(I've picked this up today but bear it in mind for future!)

Comment on lines +20 to +40
test("should count multiple occurrences of a character", () => {
const str = "aaabcde";
const char = "c";
const count = countChar(str, char);
expect(count).toEqual(1);
});

test("should count multiple occurrences of a character", () => {
const str = "a2b3c4";
const char = "3";
const count = countChar(str, char);
expect(count).toEqual(1);
});

test("should count multiple occurrences of a character", () => {
const str = "4444444444444444444";
const char = "4";
const count = countChar(str, char);
expect(count).toEqual(19);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tests should have different descriptions - here we have 3 tests, all with the same description.

There's two possible options here:

  1. Combining multiple tests into one
  2. Giving them different descriptions

Option 1 should be used when you have multiple assertions testing the same kind of behaviour. Option 2 should be used when you are testing different behaviours but have accidentally given them the same description

let countTime = 0;
for (let i = 0; i < stringOfCharacters.length; i++) {
if (stringOfCharacters.slice(i, i + 1) == findCharacter) {//take each character out from string to compare with the given character. If true, then add one to countTime.
countTime = countTime + 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This definitely works! But

stringOfCharacters.slice(i, i + 1)

is quite a lengthy way to access a single character in a string. Can you think of a simpler way?

Comment on lines +4 to +40
if (String(num).length > 1) {
//check if the number has more than 1 digit
onesDigit = Number(String(num).slice(-1)); //extract the figure at the tens digit, and convert it into a number.
const tensDigit = Number(String(num).slice(-2, -1)); //extract the figure at the tens digit, and convert it into a number.

if (onesDigit == 1) {
if (tensDigit == 1) {
return num + "th";
} else {
return num + "st";
}
} else if (onesDigit == 2) {
if (tensDigit == 1) {
return num + "th";
}
return num + "nd";
} else if (onesDigit == 3) {
if (tensDigit == 1) {
return num + "th";
}
return num + "rd";
} else {
("th");
}
} else if (String(num).length == 1) {
onesDigit = Number(String(num)[0]); //extract the figure at the tens digit, and convert it into a number.
if (onesDigit == 1) {
return num + "st";
console.log("Yeah youre in");
} else if (onesDigit == 2) {
return num + "nd";
} else if (onesDigit == 3) {
return num + "rd";
} else {
return num + "th";
}
}

@Liam310 Liam310 Jul 14, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a mostly working solution, but with a lot of nested if statements it can be quite hard to follow the logic of it.

A few things to consider:

  • You repeat the same if (tensDigit == 1) { return num + "th" } line, which suggests if the tens digit of the number is 1, you're always doing the same thing. How you might you simplify this so you only need to perform that check once?
  • On line 25 you have an else statement that doesn't contain any logic. What should that statement be doing? Why wasn't it caught by the tests?
  • The logic you have for numbers whose "length" is 1 is very similar to the logic you have for numbers whose "length" is more than 1. You could definitely make this less repetitive!
  • In a lot of places you have used == instead of === - I asked you in a previous submission what the difference was and what would be better - same question applies here!
  • You've got a leftover console.log on line 32 - get rid!

Comment on lines +21 to +42

test("should append 'nd' for numbers ending with 2, except those ending with 12", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
expect(getOrdinalNumber(22)).toEqual("22nd");
expect(getOrdinalNumber(132)).toEqual("132nd");
});

test("should append 'rd' for numbers ending with 3, except those ending with 13", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
expect(getOrdinalNumber(23)).toEqual("23rd");
expect(getOrdinalNumber(133)).toEqual("133rd");
});

test("should append 'th' for other numbers without ending with 1,2 or 3, except those ending with 1 in tens digit", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(12)).toEqual("12th");
expect(getOrdinalNumber(13)).toEqual("13th");
expect(getOrdinalNumber(113)).toEqual("113th");
expect(getOrdinalNumber(213)).toEqual("213th");
expect(getOrdinalNumber(313)).toEqual("313th");
expect(getOrdinalNumber(1113)).toEqual("1113th");
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These tests are pretty good! Though every assertion here ends in 1, 2, or 3. If you added an assertion with a number ending in a 4, what would happen? Would it pass?

Comment on lines +4 to +11
let strOutput = "";
if (count > 0){
for (let i=0 ; i<count ; i++){
strOutput = strOutput + str;
}
return strOutput;
} else if (count == 0){
return "";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This else if (count == 0) statement - what would happen if you removed it and changed the initial if statement on line 5 to if (count >= 0)? Why?

const count = -1;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("error");
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  1. The test description here doesn't match what the test is checking
  2. This isn't exactly what we want the function to do here. The instruction says "it should throw an error". I suggest you spend some time reading how to throw errors in JavaScript (see also the official MDN docs on using throw) and the Jest documentation on testing for thrown errors

@Liam310 Liam310 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 Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants