defDNAtoRNA(dna)reg_dna=/^(G|C|A|T)*$/iifdna.match(reg_dna)dna.gsub(/(T|t)/,'U').upcaseelseraise"Not a valid DNA string"endend
JavaScript
constDNAtoRNA=(dna)=>{constdnaRegex=/^(G|C|A|T)*$/giif(dnaRegex.test(dna)){returndna.replace(/t/gi,'U').toUpperCase()}else{thrownewError("Not a valid DNA string")}}
PHP
functionDNAtoRNA($dna){$dnaRegex="/^(G|C|A|T)*$/i";if(preg_match($dnaRegex,$dna)){returnstrtoupper(str_ireplace("T","U",$dna));}else{thrownew\Exception("Not a valid DNA string");};}
Super simple! I love the polyglot answers 👌🏿 Clojure
(nsdailyChallenge.206)(def-NUCLEOTIDES"Valid Nucleotides"(re-pattern"G|C|T|A|U"))(defnDNA->RNA[sequence]"validates and converts DNA pairs to RNA"{:pre[(!=""(re-matchNUCLEOTIDES(uppercasesequence))]};;Java.String method interop(.toUpperCase(replacesequence#"t|T""u")))
I wanted to see what this challenge was about, because I like these combinations of combined fields. So nice to see this come by!
But I am uncomfortable with the fact that this is not the correct way to code transcription (DNA to RNA). RNA is complementary to DNA because it is double-stranded: therefore GCAT should result in CGUA (on a side note: direction is also very important).
I'm curious if there is any particular reason why it is done in the way you described it?
fndtoa(dna:&str)->String{dna.chars().map(|c|matchc{'G'|'C'|'A'=>c,'T'=>'U',_=>panic!("you did this to yourself"),}).collect()}fnmain(){forxin&["TTTT","GCAT","GACCGCCGCC","💩"]{println!("{}=>{}",x,dtoa(x));}}
"Rust"
useitertools::Itertools;// 0.9.0#[derive(Debug)]enumDToAError{Scat(usize,char),}useDToAError::*;implstd::fmt::DisplayforDToAError{fnfmt(&self,f:&mutstd::fmt::Formatter)->std::fmt::Result{matchself{Scat(i,c)=>write!(f,"Is this a joke? At index {}, what is `{}`?! No you can't \"have the processed values back\", get out!",i,c),}}}implstd::error::ErrorforDToAError{fnsource(&self)->Option<&(dynstd::error::Error+'static)>{None}}fndtoa(dna:&str)->Result<String,DToAError>{dna.chars().enumerate().map(|(i,c)|{Ok(matchc{'G'|'C'|'A'=>c,'T'=>'U',_=>returnErr(Scat(i,c)),})}).fold_results(String::with_capacity(dna.len()),|muts,c|{s.push(c);s})}fnmain(){forxin&["TTTT","GCAT","GACCGCCGCC","💩"]{matchdtoa(x){Ok(res)=>println!("{}=>{}",x,res),Err(err)=>println!("{}=>OOPS: {}",x,err),}}}
Ruby
JavaScript
PHP
Super simple! I love the polyglot answers 👌🏿
Clojure
I wanted to see what this challenge was about, because I like these combinations of combined fields. So nice to see this come by!
But I am uncomfortable with the fact that this is not the correct way to code transcription (DNA to RNA). RNA is complementary to DNA because it is double-stranded: therefore GCAT should result in CGUA (on a side note: direction is also very important).
I'm curious if there is any particular reason why it is done in the way you described it?
Roost
"Rust"
It works lol
When you don't listen at all
Javascript solution:
C++ solution
My Swift solution :
Python solution
Elm
Ruby
Ruby