2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: afd15382cdfb22c9efe8b7de
|
|
|
|
|
challengeType: 5
|
2020-09-07 16:10:29 +08:00
|
|
|
|
forumTopicId: 16009
|
2020-10-01 17:54:21 +02:00
|
|
|
|
title: DNA 配对
|
2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Description
|
2020-09-07 16:10:29 +08:00
|
|
|
|
<section id='description'>
|
|
|
|
|
DNA 链缺少配对元素。对于每个字符,获取与其配对的元素,并将结果作为二维数组返回。
|
|
|
|
|
<a href="http://en.wikipedia.org/wiki/Base_pair" target="_blank">碱基对</a> 是一对 AT 和 CG。将缺少的元素与提供的字符匹配。
|
|
|
|
|
将提供的字符作为每个数组中的第一个元素返回。
|
|
|
|
|
例如,对于输入 GCG,返回[[“G”, “C”],[“C”, “G”],[“G”, “C”]]。
|
|
|
|
|
字符及与其配对的元素在一个数组中。再将所有数组放到一个封装数组中。
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Instructions
|
2020-09-07 16:10:29 +08:00
|
|
|
|
<section id='instructions'>
|
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
|
|
```yml
|
|
|
|
|
tests:
|
2020-09-07 16:10:29 +08:00
|
|
|
|
- text: "<code>pairElement('ATCGA')</code>应该返回<code>[['A','T'],['T','A'],['C','G'],['G','C'],['A','T']]</code>。"
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert.deepEqual(pairElement("ATCGA"),[["A","T"],["T","A"],["C","G"],["G","C"],["A","T"]]);
|
2020-09-07 16:10:29 +08:00
|
|
|
|
- text: "<code>pairElement('TTGAG')</code>应该返回<code>[['T','A'],['T','A'],['G','C'],['A','T'],['G','C']]</code>。"
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert.deepEqual(pairElement("TTGAG"),[["T","A"],["T","A"],["G","C"],["A","T"],["G","C"]]);
|
2020-09-07 16:10:29 +08:00
|
|
|
|
- text: "<code>pairElement('CTCTA')</code>应该返回<code>[['C','G'],['T','A'],['C','G'],['T','A'],['A','T']]</code>。"
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert.deepEqual(pairElement("CTCTA"),[["C","G"],["T","A"],["C","G"],["T","A"],["A","T"]]);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
function pairElement(str) {
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pairElement("GCG");
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
2020-09-07 16:10:29 +08:00
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```js
|
2020-09-07 16:10:29 +08:00
|
|
|
|
var lookup = Object.create(null);
|
|
|
|
|
lookup.A = 'T';
|
|
|
|
|
lookup.T = 'A';
|
|
|
|
|
lookup.C = 'G';
|
|
|
|
|
lookup.G = 'C';
|
|
|
|
|
|
|
|
|
|
function pairElement(str) {
|
|
|
|
|
return str.split('').map(function(p) {return [p, lookup[p]];});
|
|
|
|
|
}
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
|
2020-09-07 16:10:29 +08:00
|
|
|
|
</section>
|