Back to course home
0% completed
Vote For New Content
My Solution (JavaScript)
Jose Medina
Feb 1, 2024
class Solution { reverseVowels(s) { // TODO: Write your code here let pointerOne = s.length - 1; let pointerTwo = 0; let stringArray = Array.from(s); let hashMap = { "a": 1, "e": 1, "i": 1, "o": 1, "u": 1 } while (pointerOne >= pointerTwo) { let currentChar = stringArray[pointerOne].toLowerCase() if (hashMap[currentChar]) { let testChar = stringArray[pointerTwo].toLowerCase() if ( hashMap[testChar] ) { let holdChar = stringArray[pointerTwo]; stringArray[pointerTwo] = stringArray[pointerOne]; stringArray[pointerOne] = holdChar; pointerOne--; pointerTwo++; } else { pointerTwo++ } } else { pointerOne-- } } return stringArray.join(''); } }
0
0
Comments
Comments