Programming Questions

  • Newest
  • Popular Tags
  • Ask Question
  • Letter Changes
    Hey I have this code and it always outputs correct answers, but it says that none of the cases are passing. I'm wondering what I'm missing? function LetterChanges(str) { var alf = "abcdefghijklmnopqrstuvwxza [email protected]@##$$%%^^&&**(())__--++==~~``"; var i = 0, j =0,k=0; //var reg = /[aeiou]/g; var str1 = str.toLowerCase(); var arr = []; while(i < str1.length) { arr.push(alf.charAt(alf.indexOf(str1[i])+1)); i++; } var arr1 = arr.toString().split(",").join(""); var arr2 = arr1.replace("a","A"); var arr3 = arr2.replace("e","E"); var arr4 = arr3.replace("i","I"); var arr5 = arr4.replace("o","O"); var arr6 = arr5.replace("u","U"); return arr6; }; LetterChanges(readline());
    davjohnson posted this question on 12/21/13 | javascript, letter, changes
    Answers
  • +
  • 3
  • -
  • Hey, even when you redo the challenge and submit your new code with the global fixes it doesn't work? I just tested your new code out and it seemed to work fine for me.
  • +
  • 1
  • -
  • just to let you guys know, I have modified with global for the regexp on the replace method (see below). But stil the program is not showing any correct outputs function LetterChanges(str) { var alf = "abcdefghijklmnopqrstuvwxyza [email protected]@##$$%%^^&&**(())__--++==~~//::[[]]{{}}||\\"; var i = 0; var str1 = str.toLowerCase(); var arr = []; while(i < str1.length) { arr.push(alf.charAt(alf.indexOf(str1[i])+1)); i++; } var arr1 = arr.toString().split(",").join(""); var arr2 = arr1.replace(/[a]/g,"A"); var arr3 = arr2.replace(/[e]/g,"E"); var arr4 = arr3.replace(/[i]/g,"I"); var arr5 = arr4.replace(/[o]/g,"O"); var arr6 = arr5.replace(/[u]/g,"U"); return arr6; }; LetterChanges(readline());
  • +
  • 1
  • -
  • It turns out my PC had some adware that was minuplating all my answers, I uninstalled the program and the problem was solved.
  • +
  • 0
  • -
  • Yea, it's really weird the code works fine for all test cases, but when I submitt it I get all test cases incorrect. Maybe I'll restart my computer. lol...
  • +
  • 0
  • -
  • oh, weird I must have a browser bug... I tried to redo other questions and they're not working either
  • +
  • 0
  • -
  • Could it possible be line 7. Your while condition is (i < str1.length). This would force an off-by-one extra push command. Generally when doing these array loops i = 0 and i < (str.length -1). I think maybe you're pushing some extra whitespace into your output.
  • +
  • 0
  • -
  • I had a different solution, but encountered the same problem, all the aswers are correct(even for the ones i didn't pass), but after submitting it shows that my code didn't pass it.
  • +
  • 0
  • -
  • str.split('').map((ch, i) => { let s = (ch.toUpperCase()!= ch.toLowerCase())? String.fromCharCode(str.charCodeAt(i)+1):ch;
      return ['a','A','e','E','i','I','o','O','u','U'].includes(s)?s.toUpperCase():s  }).join('');
    
    This returns the correct output in the console but for some reason it doesn't pass the test cases.
    
    Log in to write an answer.