Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
96e54cd
Fixed the implementaton of the function CalculateMedian and passed a…
ahmadehsas Jul 28, 2025
d577680
Implemented the deduplicate function with given arrays and passed th…
ahmadehsas Jul 28, 2025
3ecbe9f
Implemented the function findMax and passed the tests for given arrays.
ahmadehsas Jul 29, 2025
0467d03
Implemented the function sum that sums the numerical elements of an a…
ahmadehsas Jul 29, 2025
a9a5914
Refactored the implementation of Includes function and passed the giv…
ahmadehsas Jul 29, 2025
d5ca4ab
Fixed the code address object and used dot notation to access the hou…
ahmadehsas Aug 5, 2025
ce7733e
Explained and fixed the problem in the mention code.
ahmadehsas Aug 6, 2025
73e8544
Fixed the mention code and printed out each ingredient in a new line …
ahmadehsas Aug 6, 2025
f512318
Implemented the function Contain, and passed tests for this function.
ahmadehsas Aug 6, 2025
22c4094
Implemented the createLookup function and passed the test.
ahmadehsas Aug 7, 2025
1231d9c
Fixed the implementation for this test and wrote tests.
ahmadehsas Aug 8, 2025
aa42568
Implemented the function called tally and passed tests.
ahmadehsas Aug 8, 2025
ef820ad
Fixed the implementation of invert function and wrote tests.
ahmadehsas Aug 9, 2025
898abfc
passed the test for contains of an array of length returns true.
ahmadehsas Aug 13, 2025
2bc209b
Fixed the code in one line with prettier-ignore.
ahmadehsas Aug 14, 2025
d0788b8
fixed the test for given an array as input return false.
ahmadehsas Aug 15, 2025
9940e55
Restore Sprint-1 folder to match main branch.
ahmadehsas Nov 12, 2025
ae98aa1
Fixed Sprint-1.
ahmadehsas Nov 21, 2025
268774e
Moved prep folder from this branch.
ahmadehsas Nov 21, 2025
9c2f2f8
checked if the code is working without if... statement.
ahmadehsas Nov 21, 2025
1f7a23d
changed the regax + to * to work for a zero characters.
ahmadehsas Nov 22, 2025
fa7c649
created an object with no prototype.
ahmadehsas Nov 22, 2025
e165bfe
modified the answers of question 'a' and 'b'.
ahmadehsas Nov 23, 2025
28a4d76
Removed unnecassary code to keep it clean.
ahmadehsas Nov 24, 2025
da2a8c5
Modified the discription of test cases on line 48 and 53.
ahmadehsas Nov 24, 2025
1cc69af
Fixed the code.
ahmadehsas Nov 24, 2025
954d882
removed unnecessary code.
ahmadehsas Nov 25, 2025
99d8f1f
updated the code.
ahmadehsas Nov 25, 2025
f0cfdc0
update the answer on line 39.
ahmadehsas Nov 25, 2025
ee378d5
Updated the answers of question a, b and d.
ahmadehsas Nov 26, 2025
f1c47e4
Fixed contains.test.js.
ahmadehsas Nov 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sprint-2/debug/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const author = {
// This means that we need to check if the property belongs to the object using hasownproperty whenever we loop through an object with the `for ... in` loop.

for (const key in author) {
if (author.hasOwnProperty(key)) {
// if (author.hasOwnProperty(key)) {
console.log(`${key}: ${author[key]}`);
}
}
//}
Copy link
Contributor

Choose a reason for hiding this comment

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

Leaving commented out unused code can make code review difficult. Can you keep the the code clean by removing all unnecessary code?
image

Copy link
Author

Choose a reason for hiding this comment

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

I removed the unnecessary code.


//for (const value of author) {
// console.log(value);
Expand Down
6 changes: 4 additions & 2 deletions Sprint-2/implement/contains.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ test("contains on an array returns false", () => {
});

test("contains on an array of length returns true", () => {
expect(contains([1, 2, 3, 4], "length")).toBe(true);
// expect(contains([1, 2, 3, 4], "length")).toBe(true);
expect(contains(null, "a", "length")).toBe(true);
}); // the test returns true because 'length' is a property of the array object

test("contains given on array as input return false", () => {
expect(contains([1, 2, 3], "a")).toBe(false);
// expect(contains([1, 2, 3], "a")).toBe(false);
expect(contains(1234, "a")).toBe(false);
});
Comment on lines 44 to 60
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these function calls return what you expect?

  contains([1, 2, 3], "0");
  contains(null, "a");
  contains(undefined, "a");
  contains(1234, "a");

Copy link
Author

Choose a reason for hiding this comment

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

My function checks for its own property on an object. For the first input `contains([1, 2, 3], "0"); return true because arrays are objects and "0" is a property key.
Inputs like 'null', 'undefined', and '123' will cause errors because they are not objects.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case you may want to update the test descriptions on lines 44 and 52.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you expect the function to accept an array as its first parameter or not? These two test descriptions are contradicting each other.

Copy link
Author

Choose a reason for hiding this comment

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

The descriptions were unclear; the function does accept an array as the first parameter. I have now updated the descriptions.
I do apologise for my emojis; I just wanted to ensure I am looking for a solution to this review.

Comment on lines 51 to 60
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check carefully what could be improved?

Copy link
Author

Choose a reason for hiding this comment

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

Missing Given /When / Then style.

Copy link
Contributor

Choose a reason for hiding this comment

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

You have all the elements in the style your mentioned. So even without those words, your description still fit the style.

I was referring to something else. Is its something that you should "fix".

6 changes: 5 additions & 1 deletion Sprint-2/implement/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ function parseQueryString(queryString) {
if (queryString.length === 0) {
return queryParams;
}

const keyValuePairs = queryString.split("&");

for (const pair of keyValuePairs) {
const [key, value] = pair.split(/=(.+)/); // We use regex to split only at first.
const [key, value] = pair.split(/=(.*)/); // We use regex to split only at first.
queryParams[key] = value;

}
Comment on lines 7 to 13
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this function call return what you expect?

  parseQuerySring("A=");  

In real query string, both key and value are percent-encoded or URL encoded.
For example,

tags%5B%5D=hello%20world -> key is tags[], value is hello world

Can your function handle URL-encoded query string?

Suggestion: Look up "How to decode a URL-encoded string in JavaScript".


return queryParams;
}
console.log(parseQueryString("A="));
console.log(decodeURIComponent("id%3D5"));

module.exports = parseQueryString;
4 changes: 3 additions & 1 deletion Sprint-2/implement/tally.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function tally(array) {
throw new Error("Input must be an array");
// check if the input ia an array. if not, throw an error.
}
const tally = {};
const tally = Object.create(null);

for (const item of array) {
tally[item] = (tally[item] || 0) + 1;
Expand All @@ -12,8 +12,10 @@ function tally(array) {
}

return tally;

}

console.log(tally(["a", "a", "a"]));
console.log(tally(["toString","toString"]));

module.exports = tally;
4 changes: 2 additions & 2 deletions Sprint-2/interpret/invert.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ console.log(invert({ a: 1, b: 2 })); // {1: "a", 2: "b"}
module.exports = invert;

// a) What is the current return value when invert is called with { a : 1 }
// The current return value is {1: "a"}
// The current return value is {'1': 'a'}

// b) What is the current return value when invert is called with { a: 1, b: 2 }
// The current return value is {1: "a", 2: "b"}
// The current return value is {'1': 'a', '2': 'b'}
Copy link
Contributor

Choose a reason for hiding this comment

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

These are still not the objects returned by the original (unmodified) function.

Copy link
Author

Choose a reason for hiding this comment

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

I have updated my code and answers


// c) What is the target return value when invert is called with {a : 1, b: 2}
// The target return value is {1: "a", 2: "b"}
Expand Down