Created
April 10, 2017 17:00
-
-
Save twalk4821/30a041e4a67011ce0a1d7dce2cab9a27 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
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