DNA Pairing - freeCodeCamp using Modern JavaScript #6

This one is actually fairly easy, so this will be a short post. We'll make a Map for the DNA base pairs and do some basic array manipulation. To see another example of Map in action take a look at the Roman Numeral Converter.

const map = new Map([['A', 'T'], ['T', 'A'], ['C', 'G'], ['G', 'C'] ]);

We can use the built-in split method to get an array of letters from a string. Then we'll map over that array to complete this exercise.

const map = new Map([['A', 'T'], ['T', 'A'], ['C', 'G'], ['G', 'C'] ]);
const pairElement = string =>
  string.split('').map(letter => [letter, map.get(letter)]);

Easy peasy 😎