Skip to content

Commit d7ce32b

Browse files
committed
Sprint 2- Lookup.js
1 parent 96d1d84 commit d7ce32b

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

Sprint-2/implement/lookup.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
function createLookup() {
2-
// implementation here
1+
function createLookup(countryCurrencyPairs) {
2+
const lookup = {};
3+
4+
for (let i = 0; i < countryCurrencyPairs.length; i++) {
5+
const countryCode = countryCurrencyPairs[i][0];
6+
const currencyCode = countryCurrencyPairs[i][1];
7+
8+
lookup[countryCode] = currencyCode;
9+
}
10+
11+
return lookup;
312
}
413

514
module.exports = createLookup;

Sprint-2/implement/lookup.test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1+
12
const createLookup = require("./lookup.js");
23

3-
test.todo("creates a country currency code lookup for multiple codes");
4+
test("creates a country currency code lookup for multiple codes", () => {
5+
const input = [
6+
["US", "USD"],
7+
["CA", "CAD"],
8+
];
9+
10+
const result = createLookup(input);
11+
12+
const expected = {
13+
US: "USD",
14+
CA: "CAD",
15+
};
416

17+
expect(result).toEqual(expected);
18+
});
519
/*
620
721
Create a lookup object of key value pairs from an array of code pairs

0 commit comments

Comments
 (0)