• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Coding Problem Problem

clickers331

New Coder
Screenshot_98.png

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.
 

Top