I am learning TypeScript and for this particular problem, I am trying to replace certain characters in a string with another character. So if there is an A, I want to replace it with a T. If there is a T, I want to replace it with an A. If there is a C, I want to replace it with a G. If there is a G, I want to replace it with a C.
The outputs would be something like this:
dnaStrand("ATTGC") // return "TAACG"
dnaStrand("GTAT") // return "CATA"
Below is my code. I decided to add an if/else statement to the static method by incorporating the include and replace method for strings. Unfortunately, it is not working. The errors I am getting seem to be syntax related. As you can see below. Can somebody help?
export class Kata {
static dnaStrand(dna: string) {
if(dna.includes('A')){
dna.replace('A', 'T')
} else if (dna.includes('T')){
dna.replace('T', 'A'){
else if (dna.includes('C')){
dna.replace('C', 'G')
}else(dna.includes('G')){
dna.replace('G', 'C')
}
}
}
}
}
Kata.dnaStrand("ATTGC")

Aucun commentaire:
Enregistrer un commentaire