Skip to content

Commit c8c25c8

Browse files
authored
Enhance createLookup function with validation
Added input validation for countryCurrencyPairs and improved error handling.
1 parent 573ace7 commit c8c25c8

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎Sprint-2/implement/lookup.js‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
function createLookup() {
2-
const lookup = {};
1+
function createLookup(countryCurrencyPairs) {
2+
const lookup = {};
33

4-
countryCurrencyPairs.forEach(pair => {
5-
lookup[pair[0]] = pair[1];
4+
if (!Array.isArray(countryCurrencyPairs)) return lookup;
5+
6+
countryCurrencyPairs.forEach((pair) => {
7+
if (!Array.isArray(pair)) return;
8+
if (pair.length < 2) return;
9+
const [country, currency] = pair;
10+
if (country == null || currency == null) return;
11+
lookup[country] = currency;
612
});
713

814
return lookup;

0 commit comments

Comments
 (0)