Skip to content

Instantly share code, notes, and snippets.

@frayhan32
Last active August 29, 2015 14:03
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 frayhan32/c44fde92c010577ea3a9 to your computer and use it in GitHub Desktop.
Save frayhan32/c44fde92c010577ea3a9 to your computer and use it in GitHub Desktop.
// Pig Latin Translator Project
// Created By Faris Rayhan
// Copyrgiht 2014
// This function will add the string at the end of string which begin by vocal with "-way"
// If begin with consonant the consonant word will be moved at the end of string plus "ay"
function toLatin(englishWord){
var string = englishword ;
var vowel = ['a','i','u','e','o'];
var result = '';
//If start with vocal
if(vowel.indexOf(string.charAt(0))!==-1){
result = englishword +'-way'
}else{
for(var i=0;i<=string.length-1;i++){
if(vowel.indexOf(string[i])!==-1){
result = string.substr(i,string.length)+"-"+string.substring(0,i)+"ay";
break ;
}
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment