Skip to content

Instantly share code, notes, and snippets.

@alexitaylor
Last active May 30, 2017 16:48
Show Gist options
  • Save alexitaylor/286679eb00e6835ca1a18362ece891a1 to your computer and use it in GitHub Desktop.
Save alexitaylor/286679eb00e6835ca1a18362ece891a1 to your computer and use it in GitHub Desktop.
/**
* Created by alexi on 5/30/17.
*/
// Given an array of characters, return the array with every vowel doubled. For example:
var input = ['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','?'];
var expectedOutput = ['w','h','a','a','t',' ','o','o','n',' ','e','e','a','a','r','t','h',' ','a','a','r','e','e',' ','y','o','o','u','u',' ','t','a','a','l','k','i','i','n','g',' ','a','a','b','o','o','u','u','t','?'];
var vowelDoubler = function(array){
var vowels = ['a', 'e', 'i', 'o', 'u'];
for (var i = 0; i < array.length; i++){
if ( vowels.includes(array[i]) ) {
var tempVowel = array[i];
var tempArray = array.splice(i, array.length);
array[i] = tempVowel;
array.push.apply(array, tempArray);
i++;
}
}
return array;
}
var output = vowelDoubler(input);
console.log(output);
var isDoubler = function (output, expectedOutput) {
var stringifyOuput = JSON.stringify(output);
var stringifyExpected = JSON.stringify(expectedOutput);
return stringifyExpected === stringifyOuput ? true : false;
}
console.log(isDoubler(output, expectedOutput)); // => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment