freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-an.../intermediate-algorithm-scri.../dna-pairing.chinese.md

2.6 KiB
Raw Blame History

id title isRequired challengeType videoUrl localeTitle
afd15382cdfb22c9efe8b7de DNA Pairing true 5 DNA配对

Description

DNA链缺少配对元素。获取每个字符获取其对并将结果作为二维数组返回。 碱基对是一对AT和CG。将缺少的元素与提供的字符匹配。将提供的字符作为每个数组中的第一个元素返回。例如对于输入GCG返回“G”“C”][“C”“G”][“G”“C”字符及其对在一个中配对数组,并将所有数组分组到一个封装数组中。如果卡住,请记得使用Read-Search-Ask 。尝试配对程序。编写自己的代码。

Instructions

Tests

tests:
  - text: '<code>pairElement(&quot;ATCGA&quot;)</code>应返回<code>[[&quot;A&quot;,&quot;T&quot;],[&quot;T&quot;,&quot;A&quot;],[&quot;C&quot;,&quot;G&quot;],[&quot;G&quot;,&quot;C&quot;],[&quot;A&quot;,&quot;T&quot;]]</code> 。'
    testString: 'assert.deepEqual(pairElement("ATCGA"),[["A","T"],["T","A"],["C","G"],["G","C"],["A","T"]], "<code>pairElement("ATCGA")</code> should return <code>[["A","T"],["T","A"],["C","G"],["G","C"],["A","T"]]</code>.");'
  - text: '<code>pairElement(&quot;TTGAG&quot;)</code>应返回<code>[[&quot;T&quot;,&quot;A&quot;],[&quot;T&quot;,&quot;A&quot;],[&quot;G&quot;,&quot;C&quot;],[&quot;A&quot;,&quot;T&quot;],[&quot;G&quot;,&quot;C&quot;]]</code> 。'
    testString: 'assert.deepEqual(pairElement("TTGAG"),[["T","A"],["T","A"],["G","C"],["A","T"],["G","C"]], "<code>pairElement("TTGAG")</code> should return <code>[["T","A"],["T","A"],["G","C"],["A","T"],["G","C"]]</code>.");'
  - text: '<code>pairElement(&quot;CTCTA&quot;)</code>应返回<code>[[&quot;C&quot;,&quot;G&quot;],[&quot;T&quot;,&quot;A&quot;],[&quot;C&quot;,&quot;G&quot;],[&quot;T&quot;,&quot;A&quot;],[&quot;A&quot;,&quot;T&quot;]]</code> 。'
    testString: 'assert.deepEqual(pairElement("CTCTA"),[["C","G"],["T","A"],["C","G"],["T","A"],["A","T"]], "<code>pairElement("CTCTA")</code> should return <code>[["C","G"],["T","A"],["C","G"],["T","A"],["A","T"]]</code>.");'

Challenge Seed

function pairElement(str) {
  return str;
}

pairElement("GCG");

Solution

// solution required