File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed
Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 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
514module . exports = createLookup ;
Original file line number Diff line number Diff line change 1+
12const 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
721Create a lookup object of key value pairs from an array of code pairs
You can’t perform that action at this time.
0 commit comments