Skip to content

Commit baf367b

Browse files
committed
add new
1 parent 03b7246 commit baf367b

File tree

7 files changed

+63
-4
lines changed

7 files changed

+63
-4
lines changed

docs/complementary-dna.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# complementary-dna
2+
3+
Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the "instructions" for the development and functioning of living organisms.
4+
5+
If you want to know more http://en.wikipedia.org/wiki/DNA
6+
7+
In DNA strings, symbols "A" and "T" are complements of each other, as "C" and "G". You have function with one side of the DNA (string, except for Haskell); you need to get the other complementary side. DNA strand is never empty or there is no DNA at all (again, except for Haskell).
8+
9+
More similar exercise are found here http://rosalind.info/problems/list-view/
10+
11+
```js
12+
complementaryDNA("ATTGC")
13+
// return "TAACG"
14+
15+
complementaryDNA("GTAT")
16+
// return "CATA"
17+
```
18+
19+
## Install
20+
21+
```
22+
$ npm install @abranhe/codewars
23+
```
24+
25+
## Usage
26+
27+
```js
28+
const codewars = require('@abranhe/codewars');
29+
30+
codewars.complementaryDNA('ATTGC');
31+
//=> 'TAACG'
32+
```
33+
34+
## API
35+
36+
### codewars.complementaryDNA(input)
37+
38+
#### input
39+
40+
Type: `string`

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ codewars.maskify('454233223424324');
2828
- [codewars.maskify()](docs/credit-card-mask.md)
2929
- [codewars.spinWords()](docs/spin-words.md)
3030
- [codewars.squareDigit()](docs/square-every-digit.md)
31+
- [codewars.complementaryDNA()](docs/complementary-dna.md)
3132

3233
## License
3334

src/complementary-dna.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = dna => {
2+
return dna
3+
.split('')
4+
.map(c => {
5+
return c === 'A' ? 'T' : c === 'T' ? 'A' : c === 'G' ? 'C' : 'G';
6+
})
7+
.join('');
8+
};

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
const maskify = require('./credit-card-mask');
44
const spinWords = require('./spin-words');
55
const squareDigits = require('./square-every-digit');
6+
const complementaryDNA = require('./complementary-dna');
67

78
module.exports = {
89
maskify,
910
spinWords,
1011
squareDigits,
12+
complementaryDNA
1113
};

src/square-every-digit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module.exports = (input) => {
2-
return Number(`${input}`.split('').map((c) => (c **= 2)).join(''));
1+
module.exports = input => {
2+
return Number(`${input}`.split('').map(c => (c * c)).join(''));
33
};

tests/complementary-dna.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import test from 'ava';
2+
import {complementaryDNA} from '../src';
3+
4+
test('Check complementary-dna.js', t => {
5+
t.is(complementaryDNA('AAAA'), 'TTTT', 'String AAAA is');
6+
t.is(complementaryDNA('ATTGC'), 'TAACG', 'String ATTGC is');
7+
t.is(complementaryDNA('GTAT'), 'CATA', 'String GTAT is');
8+
});

tests/square-every-digit.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava';
2-
import { squareDigits } from '../src';
2+
import {squareDigits} from '../src';
33

44
test('Check square-every-digit.js', t => {
5-
t.is(squareDigits(9119), 811181);
5+
t.is(squareDigits(9119), 811181);
66
});

0 commit comments

Comments
 (0)