Skip to content

Commit

Permalink
Added RNA transcription
Browse files Browse the repository at this point in the history
  • Loading branch information
zhabinka committed Jan 20, 2019
1 parent 22e1857 commit 1b2d860
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
18 changes: 18 additions & 0 deletions javascript/rna-transcription/rna-transcription.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const changer = (char) => {
switch (char) {
case 'G':
return 'C';
case 'C':
return 'G';
case 'T':
return 'A';
case 'A':
return 'U';
default:
throw new Error('Invalid input DNA.');
}
};

const toRna = dna => dna.split('').map(changer).join('');

export { toRna };
40 changes: 40 additions & 0 deletions javascript/rna-transcription/rna-transcription.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { toRna } from './rna-transcription';

describe('Transcriptor', () => {
test('empty rna sequence', () => {
expect(toRna('')).toEqual('');
});

test('transcribes cytosine to guanine', () => {
expect(toRna('C')).toEqual('G');
});

test('transcribes guanine to cytosine', () => {
expect(toRna('G')).toEqual('C');
});

test('transcribes adenine to uracil', () => {
expect(toRna('A')).toEqual('U');
});

test('transcribes thymine to adenine', () => {
expect(toRna('T')).toEqual('A');
});

test('transcribes all dna nucleotides to their rna complements', () => {
expect(toRna('ACGTGGTCTTAA'))
.toEqual('UGCACCAGAAUU');
});

test('correctly handles invalid input', () => {
expect(() => toRna('U')).toThrow(new Error('Invalid input DNA.'));
});

test('correctly handles completely invalid input', () => {
expect(() => toRna('XXX')).toThrow(new Error('Invalid input DNA.'));
});

test('correctly handles partially invalid input', () => {
expect(() => toRna('ACGTXXXCTTAA')).toThrow(new Error('Invalid input DNA.'));
});
});

0 comments on commit 1b2d860

Please sign in to comment.