Pig Latin

In this problem we are given words and we have to figure out words first character is vowel or not.then if it is vowel we have to push “way” at the end.until words first character isn’t vowel/consonant.and if word started with character that was consonant.you have to push “ay” at the very end of the word.
first of all we have to declare variable(vowel) that holds value of vowels.

^-we use this regular expression cuz we want to search vowels at the beginning.
[aeiou]-we search for a/e/i/o/u.
(+)-means that we want to keep going until there is no vowel.without it it stops searching after first character.
Then we have to watch string to vowel.

.match() — searches for matching vowel in str.
Then we have to return matching.if it doesn’t equals null then we replace vowel with an empty string.’cause we want the first character of the word to be only at the end of the word unless it’s not already a vowel at start of the word.

.replace()- replace’s first argument has to be what you want to replace and second is what you want to replace it with.
Then we want all the consonants to be at the end of the word.

.concat()- so in the matching if first characters of the word were consonants matching will have value of them and with concat function we add them at the end of the array.
lastly we have to add “ay” at the end of the array with concat() function.

So what if words first characters are vowels.we should add “way” at the end of the word with no adjustments.


? , : — it’s same as if else statement.we use them instead of if/else.
its same as this — if (matching!==null )-(?){}else -(:){}.
That was all.
Follow for more, bye!