Splitting each dna strand into own string

Hey guys I know I need to use .split() but I haven’t been able to figure out where to place it so it works. Please help me out thanks

  **Your code so far**

function pairElement(str) {
let result = [];
for (let i = 0; i < str.length; i++) {
  if (str[i] == "A") {
    result.push(str[i] + "T") // tried splitting here
  if (str[i] == "T") {
    result.push(str[i] + "A")
  if (str[i] == "C") {
    result.push(str[i] + "G")
  if (str[i] == "G") {
    result.push(str[i] + "C")

return result // tried splitting here

// [["A","T"],["T","A"],["C","G"],["G","C"],["A","T"]].

  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36.

Challenge: DNA Pairing

Link to the challenge:

you don’t need split, you need to check again what is required for each letter two

For example, for the input GCG , return [["G", "C"], ["C","G"], ["G", "C"]]

1 Like

I know the letters are correct but what do you mean by this?

I’m trying to turn 'AT’ into ["A","T"]. I believe I’m trying to turn string into array of strings. When I search that it seems the split method comes up

The return should be an array of arrays.

Try pushing an array with the current letter being iterated and the “fixed” letter. So instead of concatenating just comma separate them and push an array with both of them inside it.

someArray.push([someThingBeingLooped[index], "fixedStringValue"])
1 Like

Amazing. Thank you for breaking this down

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.