FCC-learning notes DNA Pairing, fcc-pairing

Source: Internet
Author: User

FCC-learning notes DNA Pairing, fcc-pairing

FCC-Study Notes DNA Pairing

1> I recently studied and practiced FCC questions. This is really good. I recommend it to you.

2> Chinese Version address: https://www.freecodecamp.cn/?english version address: https://www.freecodecamp.org

3> This time I wrote a question about JS called DNA Pairing.

The rules are as follows:

The DNA chain lacks a paired base. Find the matched Base Based on each base and return the result as the second array.

Base pairs (Base pair) is a pair of AT and CG, matching the missing Base for a given letter.

Returns the given letter as the first base in each array.

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

The letters and the matching letters are in a number group, and all arrays are organized and encapsulated into an array.

 

4> the code I wrote is implemented as follows:

 
function pairElement(str) {  var result=[];  var item=[];  for(var i=0;i<str.length;i++){    if(str[i]=="A"){      item=["A","T"];    }else if(str[i]=="T"){      item=["T","A"];    }else if(str[i]=="C"){      item=["C","G"];    }else if(str[i]=="G"){      item=["G","C"];    }    result.push(item);    item=[];  }  return result;}pairElement("CTCTA");pairElement("TTGAG");pairElement("GCG");

5> if there is a better method or a simple implementation, please let me know and make progress together!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.