DEV Community

Discussion on: Critique my JS solution to this CodeWars Kata

Collapse
 
moe64 profile image
Moe • Edited

I see no problem with your solution. I like how you iteratively improved your solution.

Here is my solution.

var complements = { A: 'T', T:'A', C: 'G', G: 'C'}

function DNAStrand(dna){
var dnaArray = [...dna]; //turns string into arrary , where each character is an element

 var complementArray = dnaArray.map(x => complements[x]) //maps each character with it's complement and puts the result in an array

 return complementArray.join("") //turn array into a string

}

or in one line

var complements = { A: 'T', T:'A', C: 'G', G: 'C'}

function DNAStrand(dna){
 return  [...dna].map(x => complements[x]).join("")
}
Collapse
 
ztickm profile image
Salim MAHBOUBI

Nice and clean. Thanks Maurice!