0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

js DNA塩基配列のペアを返す

Posted at

##お題
DNA塩基配列をペアにして返す。
*塩基配列

function pairDna(str) {

 return arr;
}
pairDna("ATCGA");//[["A","T"],["T","A"],["C","G"],["G","C"],["A","T"]]

出力結果 例

("TTGAG")// [["T","A"],["T","A"],["G","C"],["A","T"],["G","C"]].
("CTCTA") // [["C","G"],["T","A"],["C","G"],["T","A"],["A","T"]]

##使ったもの
split()
for文

##考え方
・オブジェクトとしてDNA塩基配列のペアをセットする。
・引数をsplitで分割して配列(arr)に入れる。
・arr[i]のペアはobj[arr[i]]で対応する。
・for文を回しておわり

##コード

function pairDna(str) {
  var obj = {T:'A', A:'T', G:'C', C:'G'};
  arr = str.split('');
  for (var i=0;i<arr.length;i++){
    arr[i]=[arr[i], obj[arr[i]]];
  }
 return arr;
}
pairDna("ATCGA");//[["A","T"],["T","A"],["C","G"],["G","C"],["A","T"]]

##他にもコードが浮かんだ方(ES6)、コメントお待ちしております。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?