-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.js
More file actions
31 lines (29 loc) · 761 Bytes
/
solution.js
File metadata and controls
31 lines (29 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* @param {string} s
* @return {string}
*/
var reverseVowels = function(s) {
let vowels = ['a', 'e', 'i', 'o', 'u']
s = s.split('')
let start = 0,
end = s.length - 1
while (start < end) {
if (vowels.findIndex(vowel => s[start].toLowerCase() === vowel) !== -1) {
while (vowels.findIndex(vowel => s[end].toLowerCase() === vowel) === -1 && start < end) {
end--
}
if (start === end) {
break
} else {
let temp = s[start]
s[start] = s[end]
s[end] = temp
start++
end--
}
} else {
start++
}
}
return s.join('')
};