DEV Community

Discussion on: Daily Challenge #175 - Complementary DNA

Collapse
 
isaacdlyman profile image
Isaac Lyman • Edited

This sounds like a one-liner in JS. Let's see...

const DNA_strand = str => str.split('').map(l => l === 'A' ? 'T' : l === 'T' ? 'A' : l === 'G' ? 'C' : l === 'C' ? 'G' : '').join('');
Enter fullscreen mode Exit fullscreen mode

As a bonus, any non-DNA letters will be ignored.

Collapse
 
vanshxrajput profile image
Vansh.c

i am fresher can you tell me what does this ( => )operator do.

Your help is appreciated.

Collapse
 
isaacdlyman profile image
Isaac Lyman

It’s an arrow function (or anonymous function).

function(a, b) {return a + b;}

Is (almost) the same as:

(a, b) => a + b

There are a few differences but most of the time they aren’t anything to worry about. If you care, this is a good overview: levelup.gitconnected.com/7-differe...