Sort by

recency

|

363 Discussions

|

  • + 0 comments

    function getLetter(s) { let letter; let a = ["a","e","i","o","u"]; let b = ["b","c", "d", "f","g"]; let c = ["h", "j", "k", "l", "m"];

    //     // Write your code here
    // return a.includes(s[0])
    //     if(a.includes(s[0])){
    
    //    return "A"
    //     }else{
    //         return "no"
    
        // }
    let firstChar = s[0]
    

    switch (true) { case a.find(item => item === firstChar) !== undefined: letter = "A"; break; case b.includes(firstChar): letter = "B"; break; case c.includes(firstChar): letter = "C"; break; default: letter = "D"; }

    return letter;
    

    }

    commented code is for understanding

  • + 0 comments
    function getLetter(s) {
      let letter;
      // Write your code here
    
      const i = 0;
      switch (true) {
        case new Set(["a", "e", "i", "o", "u"]).has(s.charAt(i)):
          letter = "A";
          break;
        case new Set(["b", "c", "d", "f", "g"]).has(s.charAt(i)):
          letter = "B";
          break;
        case new Set(["h", "j", "k", "l", "m"]).has(s.charAt(i)):
          letter = "C";
          break;
        default:
          letter = "D";
      }
    
      return letter;
    }
    
  • + 0 comments
        switch(true){
         case regex1.test(s):
           letter="A";
           break;
         case regex2.test(s):
           letter="B";
           break;
         case regex3.test(s):
           letter="C";
           break;
         case regex4.test(s):
           letter="D";
           break;  
     } 
    
  • + 0 comments
    
    

    function getLetter(s) { let letter; // Write your code here let sOne = "aeiou"; let sTwo = "bcdfg"; let sThree = "hjklm";

    switch(true){
        case (sOne.search(s[0]) != -1):
        letter = "A";
        break;
    
        case (sTwo.search(s[0]) != -1):
        letter = "B";
        break;
    
        case (sThree.search(s[0]) != -1):
        letter = "C";
        break;
    
        default:
        letter = "D";
    }
    
    return letter;
    

    }

    
    
  • + 0 comments

    function getLetters(s){ let letter; switch(true){ case /[aeiou]/i.test(s[0]): return letter = "A"; case /[bcdfg]/i.test(s[0]): return letter = "B"; case /[hjklm]/i.test(s[0]): return letter = "C"; case /[aeiou]/i.test(s[0]): return letter = "A";