-
-
Notifications
You must be signed in to change notification settings - Fork 279
Expand file tree
/
Copy pathlookup.js
More file actions
21 lines (19 loc) · 687 Bytes
/
lookup.js
File metadata and controls
21 lines (19 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function createLookup(countryCurrencyPairs) {
// Create an empty object
const lookupPairs = {};
// Loop through each pair in the array
for (let i = 0; i < countryCurrencyPairs.length; i++) {
const pair = countryCurrencyPairs[i]; // Get the current pair
const country = pair[0]; // First item is the country code
const currency = pair[1]; // Second item is the currency code
lookupPairs[country] = currency; // Add it to the object
}
return lookupPairs; // Return the final object
}
//check that it works
const pairs = [
["US", "USD"],
["CA", "CAD"],
];
console.log(createLookup(pairs)); // Output: { US: 'USD', CA: 'CAD'}
module.exports = createLookup;