-
-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathlookup.js
More file actions
27 lines (21 loc) · 660 Bytes
/
lookup.js
File metadata and controls
27 lines (21 loc) · 660 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function createLookup(pairs) {
// Check if input is an array
if (!Array.isArray(pairs)) {
return {};
}
// Create an empty object to store the lookup
const lookup = {};
// Iterate through each pair in the array
for (let i = 0; i < pairs.length; i++) {
const pair = pairs[i];
// Check if the pair is an array and has at least 2 elements
if (Array.isArray(pair) && pair.length >= 2) {
const countryCode = pair[0];
const currencyCode = pair[1];
// Add the key-value pair to the lookup object
lookup[countryCode] = currencyCode;
}
}
return lookup;
}
module.exports = createLookup;