File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ function reverseVowelsInString ( str ) {
2
+ function isVowel ( s ) {
3
+ return s == "A" || s == "E" || s == "I" || s == "O" || s == "U" || s == "a" || s == "e" || s == "i" || s == "o" || s == "u" ;
4
+ }
5
+ var vowels = [ ] ;
6
+ var indexes = [ ] ;
7
+ var newStr = str . split ( '' ) ;
8
+ for ( let i = 0 ; i < str . length ; i ++ ) {
9
+ if ( isVowel ( str [ i ] ) ) {
10
+ vowels . push ( str [ i ] ) ;
11
+ indexes . push ( i ) ;
12
+ }
13
+ }
14
+ vowels . reverse ( ) ;
15
+ for ( let i = 0 ; i < vowels . length ; i ++ ) {
16
+ newStr [ indexes [ i ] ] = vowels [ i ] ;
17
+ }
18
+ return newStr . join ( '' ) ;
19
+ }
20
+
21
+ reverseVowelsInString ( 'Acknowledgement' ) ;
22
+
23
+ /*
24
+ I was looking at a course that was having a preview for a mock interview.
25
+ The interviewer asked the interviewee to reverse all of the vowels in a string.
26
+ I wanted to work through a solution prior watching the complete mock interview.
27
+ This also works as a good practive for expanding my knowledge.
28
+ */
You can’t perform that action at this time.
0 commit comments