Created
May 30, 2017 17:15
-
-
Save chowryan/ba6fa464c7fd800c10d4b42981ad30bb 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 = 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