London | 26-ITP-May | Dagim Daniel | Sprint 2 | All Section Exercises - #1362
London | 26-ITP-May | Dagim Daniel | Sprint 2 | All Section Exercises#1362Dagim-Daniel wants to merge 6 commits into
Conversation
| test("Give invalid parameter in this case array when passed to contains it returns false", () => { | ||
| expect(contains(["a", 2, "b", 3, 2], 2)).toEqual(false); | ||
| }); |
There was a problem hiding this comment.
Should values like null, undefined, 1234, true, "ABC" be considered as invalid first parameter as well?
There was a problem hiding this comment.
// Given invalid parameters like an array
// When passed to contains
// Then it should return false or throw an error this were the question that's why i make it false.
There was a problem hiding this comment.
// Given invalid parameters like an array
That means "array" is just one possible kind of invalid parameters. There could be others.
| const result = {}; | ||
| for (const item of items) { | ||
| result[item] = (result[item] || 0) + 1; | ||
| } |
There was a problem hiding this comment.
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, or
- use
Object.hasOwn()
There was a problem hiding this comment.
it function as expected let say console.log (tally(["a","a","b","a","c"]) ==> {a:3, b:1,c:1}
There was a problem hiding this comment.
may be i don't understand your questions, could you explain your question a little bit sorry
There was a problem hiding this comment.
Have you tried calling the function with this exact argument?
tally(["toString", "toString"]);
|
Changes look good. |
Learners, PR Template
Self checklist
Changelist
i have completed all section tasks under Sprint 2, but i have commited separetly in this PR