Skip to content

Instantly share code, notes, and snippets.

@chowryan
Created May 30, 2017 17:15
Show Gist options
  • Save chowryan/ba6fa464c7fd800c10d4b42981ad30bb to your computer and use it in GitHub Desktop.
Save chowryan/ba6fa464c7fd800c10d4b42981ad30bb to your computer and use it in GitHub Desktop.
const vowelDoubler = array => {
const vowels = ['a', 'e', 'i', 'o', 'u'];
let resultLength = array.length;
for (let i = 0; i < array.length; i += 1) {
if (vowels.includes(array[i])) {
resultLength += 1;
}
}
let offset = resultLength - array.length;
for (let i = resultLength - 1; i >= 0; i -= 1) {
if (vowels.includes(array[i - offset])) {
array[i] = array[i - offset];
array[i - 1] = array[i - offset];
// offset += 1;
// temp2 = array[i + 2];
// array[i + 2] = temp;
offset -= 1;
i -= 1;
} else {
array[i] = array[i - offset];
}
}
return array;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment