Skip to content

Instantly share code, notes, and snippets.

@twalk4821
Created April 10, 2017 17:00
Show Gist options
  • Save twalk4821/30a041e4a67011ce0a1d7dce2cab9a27 to your computer and use it in GitHub Desktop.
Save twalk4821/30a041e4a67011ce0a1d7dce2cab9a27 to your computer and use it in GitHub Desktop.
var vowelDoubler = function(arr) {
vowels = {'a':'a', 'i':'i', 'o':'o', 'u':'u', 'e':'e'}
var count = arr.reduce(function (acc, next) {
return next in vowels ? acc++ : acc;
});
console.log(count)
//hard coded count because reduce function doesn't seem to work
count=1;
j = arr.length+count-1;
for (var i=arr.length-1; i>=0; i--) {
console.log(i, j, arr)
if (arr[i] in vowels) {
arr[j] = arr[i];
arr[j-1] = arr[i];
j = j-2;
} else {
arr[j] = arr[i];
j--;
}
}
return arr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment