Simple Javascript es6 Solution


  • 0
    R
    var reverseVowels = function(s) {
      const vowels = 'aeiouAEIOU'
      let result = []
      let stripped = []
    
      for (let ch of s) {
        if (vowels.indexOf(ch) !== -1) {
          stripped.push(ch)
        }
      }
    
      let index = stripped.length - 1
      for (let ch of s) {
        if (vowels.indexOf(ch) !== -1) {
          result.push(stripped[index])
          index--
        } else {
          result.push(ch)
        }
      }
    
      return result.join('')
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.