Skip to content

Commit 5eee074

Browse files
committed
throw an error instead
1 parent e903450 commit 5eee074

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Sprint-2/implement/lookup.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
function Lookup(countryCurrencyPairs) {
88
// check if the argument is an array of arrays
99
if (
10-
Array.isArray(countryCurrencyPairs) &&
10+
!Array.isArray(countryCurrencyPairs) ||
1111
// check if each inner array is an array.
12-
countryCurrencyPairs.every((pair) => Array.isArray(pair)) &&
12+
!countryCurrencyPairs.every((pair) => Array.isArray(pair)) ||
1313
// check if each inner array has two elements.
14-
countryCurrencyPairs.every((pair) => pair.length === 2)
14+
!countryCurrencyPairs.every((pair) => pair.length === 2)
1515
// we can also use index to check the pair is an array as follows:
1616
// for (let i = 0; i < countryCurrencyPairs.length; i++)
1717
// return Array.isArray(countryCurrencyPairs[i])
1818
) {
19-
return Object.fromEntries(countryCurrencyPairs);
19+
throw new Error("Invalid input: expected an array of arrays");
2020
}
21-
return "Invalid input: expected an array of arrays";
21+
return Object.fromEntries(countryCurrencyPairs);
2222
}
2323

2424
module.exports = Lookup;

0 commit comments

Comments
 (0)