2 回答
TA贡献1878条经验 获得超4个赞
mRNA.concat(b);不会改变字符串,它只会计算值。您需要mRNA = mRNA.concat(b)(或mRNA = mRNA + b)更改的值mRNA。
TA贡献1790条经验 获得超9个赞
您可以考虑将任务包装到函数中,而不是尝试在上限范围内对变量进行突变。
让我们对其进行重构,以确保m_RNA返回正确的映射:
var DNA = "TAG";
// create a map so every char maps to something.
const map = {
T: 'A',
A: 'U',
C: 'G',
G: 'C',
};
// check only needs to pick from map, or return an empty string.
function check(fragment) {
return map[fragment] || '';
}
function m_RNA(dna) {
// reduces all the chars to the new sequence
return Array.from(dna).reduce(
function (result, fragment) {
return result.concat(check(fragment))
},
"",
);
}
var mRNA = m_RNA(DNA);
console.log('mRNA', mRNA);
添加回答
举报
