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!