Skip to content

WESTMIDLANDS JAN ITP|SEGUN FOLAYAN|DATA-GROUPS|SPRINT-2 #475

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 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion Sprint-2/debug/address.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Predict and explain first...
//The houseNumber will print out as undefined

// This code should log out the houseNumber from the address object
// but it isn't working...
Expand All @@ -12,4 +13,4 @@ const address = {
postcode: "XYZ 123",
};

console.log(`My house number is ${address[0]}`);
console.log(`My house number is ${address.houseNumber}`);
3 changes: 2 additions & 1 deletion Sprint-2/debug/author.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Predict and explain first...
//The program will not tun because author in not an

// This program attempts to log out all the property values in the object.
// But it isn't working. Explain why first and then fix the problem
Expand All @@ -11,6 +12,6 @@ const author = {
alive: true,
};

for (const value of author) {
for (const value of Object.values(author)) {
console.log(value);
}
3 changes: 2 additions & 1 deletion Sprint-2/debug/recipe.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Predict and explain first...
//The programme will not print out the ingredients. To print out the ingredients we need ${recipe.ingredients.join("\n")}

// This program should log out the title, how many it serves and the ingredients.
// Each ingredient should be logged on a new line
Expand All @@ -12,4 +13,4 @@ const recipe = {

console.log(`${recipe.title} serves ${recipe.serves}
ingredients:
${recipe}`);
${recipe.ingredients.join("\n")}`);
10 changes: 9 additions & 1 deletion Sprint-2/implement/contains.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
function contains() {}


function contains(obj, prop) {
if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
return false;
}
return obj.hasOwnProperty(prop);
}

module.exports = contains;

15 changes: 13 additions & 2 deletions Sprint-2/implement/contains.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,27 @@ as the object doesn't contains a key of 'c'
// Given an empty object
// When passed to contains
// Then it should return false
test.todo("contains on empty object returns false");
test("contains on empty object returns false", ()=> {
expect(contains({},"a")).toBe(false)
});

// Given an object with properties
// When passed to contains with an existing property name
// Then it should return true
test("if existing property,should return false", ()=> {
expect(contains({a: 1, b: 2}, 'a')).toBe(true)
});

// Given an object with properties
// When passed to contains with a non-existent property name
// Then it should return false
// Then it should return falsetest
test("if non-existing property,should return false", ()=> {
expect(contains({a: 1, b: 2}, 'c')).toBe(false)
});

// Given invalid parameters like an array
// When passed to contains
// Then it should return false or throw an error
test("if an array,should return false", ()=> {
expect(contains(["a", "b"], 'a')).toBe(false)
});
12 changes: 10 additions & 2 deletions Sprint-2/implement/lookup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
function createLookup() {
// implementation here
function createLookup(countryCurrencyPairs) {
return countryCurrencyPairs.reduce((acc,[country,currency]) => {
acc[country] = currency;
return acc;
}, {});

}

module.exports = createLookup;




16 changes: 15 additions & 1 deletion Sprint-2/implement/lookup.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
const createLookup = require("./lookup.js");

test.todo("creates a country currency code lookup for multiple codes");
test("creates a country currency code lookup for multiple codes", ()=> {
expect(createLookup([['US', 'USD'], ['CA', 'CAD']])).toEqual({
'US': 'USD',
'CA': 'CAD'
});
});

/*

test("creates a country currency code lookup for multiple codes", () => {
expect(createLookup([['US', 'USD'], ['CA', 'CAD']])).toEqual({
'US': 'USD',
'CA': 'CAD'
});
});



Create a lookup object of key value pairs from an array of code pairs

Acceptance Criteria:
Expand Down
Loading