repl.it
@QuemuelVital/

DNA Pairing

Nodejs

The DNA strand is missing the pairing element. Take each character, get its pair, and return the results as a 2d array.

fork
loading
Files
  • index.js
index.js
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
28
29
30
31
32
33
34
35
function pairElement(str) {
  let arr = [[]];

  arr = str.split('');

  for(let i = 0; i < str.length; i++){
    switch (arr[i]){
    case 'G':
      arr[i] = ["G", "C"];
      console.log(arr);
      break;

    case 'C':
      arr[i] = ["C", "G"];
      console.log(arr);
      break;

    case 'T':
      arr[i] = ["T", "A"];
      console.log(arr);
      break;
    
    case 'A':
      arr[i] = ["A", "T"];
      console.log(arr);
      break;
    }
    
  }
  return arr;
}
  
pairElement("ATCGA");

// Implement an object and a map function to clean and declarative algorithm.