-
-
Notifications
You must be signed in to change notification settings - Fork 193
Glasgow | ITP-SEP-25 | Alaa Tagi | Sprint 2 | Coursework/sprint 2 #886
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
base: main
Are you sure you want to change the base?
Conversation
| function countWords(inputString) { | ||
|
|
||
| const cleanedString = inputString.replace(/[.,!?]/g, '').toLowerCase(); | ||
| const wordsArray = cleanedString.split(/\s+/); | ||
| const wordCount = {}; | ||
|
|
||
| for (const word of wordsArray) { | ||
| if (wordCount[word] === undefined) { | ||
| wordCount[word] = 1; | ||
| } else { | ||
| wordCount[word]++; | ||
| } | ||
| } | ||
|
|
||
| return wordCount; | ||
| } |
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.
Change is optional.
Here are some test cases you can try when you have time.
countWords("constructor constructor");
countWords(" Hello World ");
| test("totalTill calculates the total amount in pounds from the till object", () => { | ||
| const till = { | ||
| "1p": 10, | ||
| "5p": 6, | ||
| "50p": 4, | ||
| "20p": 10, | ||
| }; | ||
|
|
||
| expect(totalTill(till)).toBe("£4.10"); | ||
| }); | ||
|
|
||
| // Additional test cases | ||
| test("totalTill returns £0.00 for an empty till", () => { | ||
| const till = {}; | ||
|
|
||
| expect(totalTill(till)).toBe("£0.00"); | ||
| }); | ||
|
|
||
| test("totalTill handles tills with only one type of coin", () => { | ||
| const till = { | ||
| "100p": 5, | ||
| }; | ||
|
|
||
| // d) Write a test for this function to check it works and then fix the implementation of totalTill | ||
| expect(totalTill(till)).toBe("£5.00"); | ||
| }); |
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 your function pass all these tests?
cjyuan
left a comment
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.
Changes are good.
It's best practice to also respond to each of reviewer's comments.
| recipe.ingredients.forEach(ingredient => { | ||
| console.log(ingredient); | ||
| }); |
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.
This work. Could also explore Array.prototype.join().
| if (firstEq === -1) { | ||
| // No "=" found → key with empty value | ||
| key = decodeURIComponent(pair); | ||
| value = ""; | ||
| } else { | ||
| key = decodeURIComponent(pair.slice(0, firstEq)); | ||
| value = decodeURIComponent(pair.slice(firstEq + 1)); | ||
| } | ||
|
|
||
| queryParams[key] = value; |
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.
Could also consider performing the decoding step on line 31.
Learners, PR Template
Self checklist
Changelist
I have completed the tasks required in this sprint.
Questions
No questions.