-
-
Notifications
You must be signed in to change notification settings - Fork 153
Sheffield | May-2025 | Waleed-Yahya Salih-Taha | DataGroup-sprint 2 #672
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
removed extra space.
…ty object with test one
added the test code in the invert.js file and run the test all passed.
Run the test and passed all of it.
… returns an object. Added all the advanced challenges and tested them.
…p in this function?
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) { | ||
return false; | ||
} | ||
return Object.prototype.hasOwnProperty.call(obj, key); |
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 use Object.hasOwn(obj, key)
.
|
||
// Given invalid parameters like an array | ||
// When passed to contains | ||
// Then it should return false or throw an error | ||
test("contains on array returns false", () => { | ||
expect(contains([1, 2, 3], 'a')).toBe(false); |
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.
contains([1, 2, 3], "a")
could also return false because "a" is not a property (or key) of [1, 2, 3]
.
However, "0", "1", "2" are keys of [1, 2, 3]
, so it is better to specify the test as
expect(contains([1, 2, 3], "1")).toBe(false);
(to ensure you are checking what you describe)
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 file Sprint-2/implement/querystring.js
(which contains the implementation of the function) was not updated.
function tally(arr) { | ||
if (!Array.isArray(arr)) { | ||
throw new Error("Input must be an array"); | ||
} | ||
return arr.reduce((acc, item) => { | ||
acc[item] = (acc[item] || 0) + 1; | ||
return acc; | ||
}, {}); | ||
} |
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"]);
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.
What is this file for?
const words = cleanedStr.split(/\s+/); | ||
|
||
// Create an object to store word counts | ||
const wordCount = {}; | ||
|
||
for (let word of words) { | ||
if (wordCount[word]) { | ||
wordCount[word]++; | ||
} else { | ||
wordCount[word] = 1; | ||
} | ||
} | ||
|
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 you check if your function returns what you expect in the following function calls?
countWords("Hello,World! Hello World!");
countWords("constructor constructor");
countWords(" Hello World ");
|
||
// Optional: Sort the results by frequency (most common first) | ||
const sortedWordCount = Object.fromEntries( | ||
Object.entries(wordCount).sort((a, b) => b[1] - a[1]) |
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.
In (a, b) => b[1] - a[1]
, it is not clear what the 2nd element of the parameters represents.
Can you think of a way to make the code more readable? (Hint: Use array destructuring on the parameters).
total += coin * quantity; | ||
for (const [coin, quantity] of Object.entries(till)) { | ||
// Remove the "p" and convert to number | ||
const coinValue = parseInt(coin.replace("p", ""), 10); |
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 you find out why the following statement work equally well (compare to the statement at line 12)?
const coinValue = parseInt(coin);
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.
Sprint-3/quote-generator/index.html
does not belong to Sprint-2. Can you revert the change to this file?
Learners, PR Template
Self checklist
Changelist
this PR gives a short set of requirements about a function. and You will need to implement, interpret and and sometimes fix a function based off this set of requirements
Questions
Ask any questions you have for your reviewer.