Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arrbxr/db34313b2671f1b68a8ca7d11be491c5 to your computer and use it in GitHub Desktop.
Save arrbxr/db34313b2671f1b68a8ca7d11be491c5 to your computer and use it in GitHub Desktop.
Replace all vowel to exclamation mark in the sentence created by arrbxr - https://repl.it/@arrbxr/Replace-all-vowel-to-exclamation-mark-in-the-sentence
// Replace all VOWEL to EXCLAMATION
function vowelReplace(str){
// here we define vowel
var myStr = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'];
// here we convert string to array
var arr = str.split('')
// first loop start
for(i = 0; i < arr.length; i++){
// second loop start
for(j = 0; j< myStr.length; j++){
// we compare i and j
if(arr[i] == myStr[j]){
// here vowel convert exclamation
arr[i] = "!";
}
}
}
// here join() function replace array to string
return arr.join('');
}
vowelReplace("Replace All vowel to exclamation");
@arrbxr
Copy link
Author

arrbxr commented Feb 18, 2018

// second method
function replace(s){
return s.replace(/[aeoiu]/ig, '!')
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment