-
Notifications
You must be signed in to change notification settings - Fork 1
/
DEV#175.js
50 lines (47 loc) · 1.06 KB
/
DEV#175.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// https://dev.to/thepracticaldev/daily-challenge-174-soccer-league-table-2393
function DNA_strand (str) {
let result = ''
for (let i = 0; i < str.length; i++) {
switch (str[i]) {
case 'A':
result = result + 'T'
break
case 'T':
result = result + 'A'
break
case 'C':
result = result + 'G'
break
case 'G':
result = result + 'C'
break
default:
return 'Your DNA is not from this planet'
}
}
return result
};
// Tests
const cases = [
{
label: 'ATTGC',
input: DNA_strand('ATTGC'),
shouldBe: 'TAACG'
},
{
label: 'GTTAAC',
input: DNA_strand('GTTAAC'),
shouldBe: 'CAATTG'
},
{
label: 'AAAA',
input: DNA_strand('AAAA'),
shouldBe: 'TTTT'
},
{
label: 'Invalid DNA',
input: DNA_strand('CTHCC'),
shouldBe: 'Your DNA is not from this planet'
}
]
cases.map(test => console.log((test.input === test.shouldBe ? '✅' : '❗') + ' ' + test.label + ' => ' + 'Should be: ' + test.shouldBe + ' received: ' + test.input))