-
-
Notifications
You must be signed in to change notification settings - Fork 190
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
Sprint-2/debug/recipe.js
Outdated
| ${recipe.ingredients[0] | ||
| } | ||
| ${recipe.ingredients[1]} | ||
| ${recipe.ingredients[2]} | ||
| ${recipe.ingredients[3]} |
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 approach works only when there are exactly 4 ingredients.
Can you figure out a more general approach that works on any number of ingredients?
| } | ||
| 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.
Please note that in real querystring, both key and value are percent-encoded or URL encoded in the URL. For example, the string "5%" will be encoded as "5%25". So to get the actual value of "5%25" (whether it is a key or value in the querystring), we should call a function to decode it.
May I suggest looking up any of these terms, and "How to decode URL encoded string in JS"?
Sprint-2/implement/tally.js
Outdated
| if (!Array.isArray(items)) { | ||
| throw new TypeError('Input must be an array'); | ||
| } | ||
| const tallyResult = {}; |
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.
Does the following function call returns the value you expect?
tally(["toString", "toString"]);
Suggestion: Look up an approach to create an empty object with no inherited properties.
| 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 ");
Sprint-2/stretch/mode.test.js
Outdated
| test("calculateMode is a function ,returns the most frequent number", () => { | ||
| const nums = [1, 2, 2, 3, 4]; | ||
|
|
||
| expect(typeof calculateMode).toBe("function"); | ||
| expect(calculateMode(nums)).toBe(2); | ||
| }); |
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.
The objective of this stretch exercise is to decompose the code in the calculateMode function in mode.js into two functions.
| 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?
Learners, PR Template
Self checklist
Changelist
I have completed the tasks required in this sprint.
Questions
No questions.