Skip to content

Instantly share code, notes, and snippets.

@kennyxcao
Created October 23, 2017 16:33
Show Gist options
  • Save kennyxcao/7b3e5cecf5cd3404adc3fb48da65e1ef to your computer and use it in GitHub Desktop.
Save kennyxcao/7b3e5cecf5cd3404adc3fb48da65e1ef to your computer and use it in GitHub Desktop.
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