clickers331
New Coder

This is the problem I am trying to solve.
JavaScript:
export const translate = (RNA) => {
let database = {
Methionine : ["AUG"],
Phenylalanine : ["UUU", "UUC"],
Leucine : ["UUA", "UUG"],
Serine : ["UCU", "UCC", "UCA", "UCG"],
Tyrosine : ["UAU", "UAC"],
Cysteine : ["UGU", "UGC"],
Tryptophan : ["UGG"],
STOP : ["UAA", "UAG", "UGA"]
}
if (RNA === undefined){
return [];
}
let rnaArr = RNA.split('');
let colons = [];
let sequence = [];
let proteins = [];
for (let i = 0; i < rnaArr.length; i++){
sequence.push(rnaArr[i]);
if((i + 1) % 3 === 0){
colons.push(sequence.join(''));
sequence = [];
}
}
if (colons.includes(...database.Methionine)){
proteins.push("Methionine")
} if (colons.includes(...database.Phenylalanine)){
proteins.push("Phenylalanine")
} if (colons.includes(...database.Leucine)){
proteins.push("Leucine")
} if (colons.includes(...database.Serine)){
proteins.push("Serine")
} if (colons.includes(...database.Tyrosine )){
proteins.push("Tyrosine")
} if (colons.includes(...database.Tryptophan)){
proteins.push("Tryptophan")
} if (colons.includes(...database.STOP)){
proteins.push("STOP")
} if (proteins === []){
return "Invalid colon.";
}
return proteins;
};
I wasn't able to solve it so if I could get any kind of help, it would be much appreciated.