DNA Pairing-freecodecamp Algorithm Topics

Source: Internet
Author: User

DNA Pairing

1. Requirements

    • The DNA Strand lacks a paired base. Based on each base, the matching base is found, and the result is returned as a second array.
    • Base pairs (base pair) is a pair of at and CG that matches the missing base for a given letter.
    • The letters and the letters to which they are paired are inside an array, and then all the arrays are organized and encapsulated into an array.

2. Ideas

    • Use. Split (") to divide the entered letter string into an alphabetic array
    • Define the result array variable, traverse each given letter in the for loop, push to the two-dimensional element of the result array, use the switch statement to determine the base of each letter pair, push to the corresponding array
    • Returns an array of results

3. Code

function pair(str) {var result=[];var temp = str.split(‘‘);for(var i=0;i<temp.length;i++){    result[i]=[];    result[i].push(temp[i]);    switch(temp[i]){        case ‘A‘: result[i].push(‘T‘);break;        case ‘T‘: result[i].push(‘A‘);break;        case ‘G‘: result[i].push(‘C‘);break;        case ‘C‘: result[i].push(‘G‘);break;    }}return result;}pair("GCG");

4. RELATED LINKS

    • Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/push
    • Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/split
    • Http://en.wikipedia.org/wiki/Base_pair

DNA Pairing-freecodecamp Algorithm Topics

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.