Skip to content

ITP-Jan | NW | Jovy So | Module-Data-Groups | WEEK 2 #508

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
6 changes: 5 additions & 1 deletion Sprint-2/debug/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ const recipe = {

console.log(`${recipe.title}
serves ${recipe.serves}
ingredients: ${recipe.ingredients}`);
ingredients:`);

for (let ingredient of recipe.ingredients) {
console.log(ingredient);
}
5 changes: 3 additions & 2 deletions Sprint-2/implement/contains.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function contains(object, propertyName) {
// console.log(propertyName, '<-- property name');
if (!propertyName) return false;
if (!object) return false;
// if (!propertyName) return false;
// if (!object) return false;
if (typeof object !== "object" || object === null || Array.isArray(object) || typeof object === "string") return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

This check is, typeof object === "string", is not needed because a string is not an object; the first condition would already be true.

if (object.hasOwnProperty(propertyName)) return true;
else return false;
};
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 @@ -28,7 +28,7 @@ expect(contains({a: 1, b: 2})).toEqual(false);
// When passed to contains
// Then it should return false
test("contains on empty object returns false", () => {
expect(contains()).toEqual(false);
expect(contains({}, "a")).toEqual(false);
});

// Given an object with properties
Expand All @@ -49,5 +49,7 @@ test("not contains the property in the object returns false", () => {
// When passed to contains
// Then it should return false or throw an error
test("contains invalid parameters return false", () => {
expect(contains([1,2,3])).toEqual(false);
expect(contains([1,2,3], '0')).toEqual(false);
expect(contains("ABC", '0')).toEqual(false);
expect(contains(null, 'a')).toEqual(false);
});
6 changes: 4 additions & 2 deletions Sprint-2/implement/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ function parseQueryString(queryString) {

for (const pair of keyValuePairs) {
const [key, value] = pair.split(/=(.*)/s);
queryParams[key] = value;
// queryParams[key] = value;
queryParams[decodeURIComponent(key)] = decodeURIComponent(value);
}

return queryParams;
}

module.exports = parseQueryString;

console.log(parseQueryString("equation=x=y+1"));
console.log(parseQueryString("equation=x=y+1"));
console.log(parseQueryString("5%25"));