DEV Community

duccanhole
duccanhole

Posted on

code every day with me

--DAY 26--

Hi, I am going to make #100DaysOfCode Challenge. Everyday I will try solve 1 problem from leetcode or hackerrank. Hope you can go with me until end.
Now let's solve problem today:
Problem: Isomorphic Strings
Detail: here
My solution (javascript):

var reverseVowels = function(s) {
    s=s.split('');
    let vowel = ['a','e','i','o','u','A','E','I','O','U'];
    let i=0,j=s.length-1;
    while(i<j){
        if(!vowel.includes(s[i])) i++;
        else if(!vowel.includes(s[j])) j--;
        if(vowel.includes(s[i])&&vowel.includes(s[j])){
            [s[i],s[j]]=[s[j],s[i]];
            i++;
            j--;
        }
    }
    return s.join('');
};
Enter fullscreen mode Exit fullscreen mode

-->If you have better solution or any question, please comment below. I will appreciate.

Discussion (0)