Skip to content

Commit 6d4aa98

Browse files
committed
RNA transcription solution
1 parent 5b6aa08 commit 6d4aa98

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

rna-transcription/README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Rna Transcription
2+
3+
Given a DNA strand, return its RNA complement (per RNA transcription).
4+
5+
Both DNA and RNA strands are a sequence of nucleotides.
6+
7+
The four nucleotides found in DNA are adenine (**A**), cytosine (**C**),
8+
guanine (**G**) and thymine (**T**).
9+
10+
The four nucleotides found in RNA are adenine (**A**), cytosine (**C**),
11+
guanine (**G**) and uracil (**U**).
12+
13+
Given a DNA strand, its transcribed RNA strand is formed by replacing
14+
each nucleotide with its complement:
15+
16+
* `G` -> `C`
17+
* `C` -> `G`
18+
* `T` -> `A`
19+
* `A` -> `U`
20+
21+
## Setup
22+
23+
Go through the setup instructions for JavaScript to
24+
install the necessary dependencies:
25+
26+
http://exercism.io/languages/javascript
27+
28+
## Making the Test Suite Pass
29+
30+
Execute the tests with:
31+
32+
jasmine-node .
33+
34+
In many test suites all but the first test have been skipped.
35+
36+
Once you get a test passing, you can unskip the next one by
37+
changing `xit` to `it`.
38+
39+
## Source
40+
41+
Rosalind [http://rosalind.info/problems/rna](http://rosalind.info/problems/rna)
42+
43+
## Submitting Incomplete Problems
44+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
45+
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const DnaTranscriber = function () {};
2+
3+
const convTable = {
4+
"G": "C",
5+
"C": "G",
6+
"T": "A",
7+
"A": "U"
8+
};
9+
10+
DnaTranscriber.prototype.toRna = function (dna) {
11+
return Array
12+
.from(dna)
13+
.map(nucleotide => {
14+
const rnaNucleotide = convTable[nucleotide];
15+
if (rnaNucleotide) {
16+
return rnaNucleotide;
17+
} else {
18+
throw new Error('Invalid input');
19+
}
20+
}).join('');
21+
};
22+
23+
module.exports = DnaTranscriber;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var DnaTranscriber = require('./rna-transcription');
2+
var dnaTranscriber = new DnaTranscriber();
3+
4+
describe('toRna()', function() {
5+
6+
it('transcribes cytosine to guanine', function() {
7+
expect(dnaTranscriber.toRna('C')).toEqual('G');
8+
});
9+
10+
it('transcribes guanine to cytosine', function() {
11+
expect(dnaTranscriber.toRna('G')).toEqual('C');
12+
});
13+
14+
it('transcribes adenine to uracil', function() {
15+
expect(dnaTranscriber.toRna('A')).toEqual('U');
16+
});
17+
18+
it('transcribes thymine to adenine', function() {
19+
expect(dnaTranscriber.toRna('T')).toEqual('A');
20+
});
21+
22+
it('transcribes all dna nucleotides to their rna complements', function() {
23+
expect(dnaTranscriber.toRna('ACGTGGTCTTAA'))
24+
.toEqual('UGCACCAGAAUU');
25+
});
26+
27+
it('correctly handles completely invalid input', function () {
28+
expect(function () { dnaTranscriber.toRna('XXX') }).toThrow(
29+
new Error('Invalid input')
30+
);
31+
});
32+
33+
it('correctly handles partially invalid input', function () {
34+
expect(function () { dnaTranscriber.toRna('ACGTXXXCTTAA') }).toThrow(
35+
new Error('Invalid input')
36+
);
37+
});
38+
});

0 commit comments

Comments
 (0)