The Kata
The exercice basically asks to convert any 'T' to 'A' any 'C' to 'G' and vice versa for any given string.
My solution...
For further actions, you may consider blocking this person and/or reporting abuse
Defaulting to
const
declarations helps keep track of what's allowed to change.reduce
is more appropriate when you need to accumulate results than the two-step of generating a new array andjoin
ing it. The hashtable lookup keeps the reducer body as short as possible, but there's nothing wrong with aswitch
per se.@dmfay This is a very elegant solution! I like that you're explaining the reasons why you did things like use a
const
etc.One thing you didn't mention is the use of the spread syntax (
[...dna]
), which is definitely handy in JS when passing arrays around.wow I didn't know
would automatically turn your string into an array. I always use
I'm gonna change my solution to reflect this newfound knowledge.
Came to the comments to post this exact solution. Very elegantly done.
Clever!
Thanks Dian!
Thanks Sean ! I don't know why I didn't think of reduce...
I see no problem with your solution. I like how you iteratively improved your solution.
Here is my solution.
or in one line
Nice and clean. Thanks Maurice!