Created
October 23, 2017 16:33
-
-
Save kennyxcao/7b3e5cecf5cd3404adc3fb48da65e1ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const vowelDoubler = function (array) { | |
| let count = 0; | |
| for (let i = 0; i < array.length; i++) { | |
| if (['a', 'e', 'i', 'o', 'u'].includes(array[i])) { | |
| count++; | |
| } | |
| } | |
| for (let i = array.length - 1, j = i + count; i >= 0; i--, j--) { | |
| array[j] = array[i]; | |
| if (['a', 'e', 'i', 'o', 'u'].includes(array[j])) { | |
| array[j - 1] = array[j]; | |
| j--; | |
| } | |
| } | |
| return array; | |
| }; | |
| // Tests | |
| let double = vowelDoubler(['w', 'h', 'a', 't', ' ', 'o', 'n', ' ', 'e', 'a', 'r', 't', 'h', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u', ' ', 't', 'a', 'l', 'k', 'i', 'n', 'g', ' ', 'a', 'b', 'o', 'u', 't', '?']); | |
| console.log(double); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment