Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

WM5 | AISHA_ATHMAN_LALI | MODULE_JS2 | WEEK2 #81

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add function and tests for lookup
  • Loading branch information
aishaathmanlali committed Nov 9, 2023
commit e01d809d20a81cd71345d4a422745f404fedabda
44 changes: 33 additions & 11 deletions week-2/implement/lookup.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
function createLookup() {
// implementation here
function createLookup(arrays) {
const countryCurrency = {};

if (Array.isArray(arrays[0])) {
for (const array of arrays) {
const [key, value] = array;
countryCurrency[key] = value;
}
} else {
const [key, value] = arrays;
countryCurrency[key] = value;
}

return countryCurrency;
}

console.log(createLookup(["KE", "KSH"]));
console.log(
createLookup([
["KE", "KSH"],
["TR", "TRY"],
])
);

module.exports = createLookup;

/* ======= Test suite is provided below... =====
*/

test("converts a single pair of currency codes", () => {
expect(createLookup([["GB", "GBP"]])).toEqual({
GB: "GBP",
});
expect(createLookup([["DE", "EUR"]])).toEqual({
DE: "EUR",
});
});
// test("converts a single pair of currency codes", () => {
// expect(createLookup([["GB", "GBP"]])).toEqual({
// GB: "GBP",
// });
// expect(createLookup([["DE", "EUR"]])).toEqual({
// DE: "EUR",
// });
// });

test.todo("creates a country currency code lookup for multiple codes");
// test.todo("creates a country currency code lookup for multiple codes");
20 changes: 20 additions & 0 deletions week-2/implement/lookup.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const createLookup = require("./lookup.js");
/*

Create a lookup object of key value pairs from an array of code pairs
Expand Down Expand Up @@ -29,3 +30,22 @@ It should return:
'CA': 'CAD'
}
*/
test("converts a single pair of currency codes", () => {
expect(createLookup([["KE", "KSH"]])).toEqual({
KE: "KSH",
});
expect(createLookup([["DE", "EUR"]])).toEqual({
DE: "EUR",
});
});

test("creates a country currency code lookup for multiple codes", () => {
expect(createLookup([["GB", "GBP"],["KE", "KSH"]])).toEqual({
GB: "GBP",
KE: "KSH"
});
expect(createLookup([["DE", "EUR"],["TR", "TRY"]])).toEqual({
DE: "EUR",
TR: "TRY"
});
});