Pig Latin

problem

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.

replaces vowel with a string.

.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.

adds parameter 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.

solution

? , : — 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!

Unlisted

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

React Basic

Lift NodeJS App with PM2

What is strict mode in Javascript

Time for a Quick(er) Cypress Visit in Angular

Refresh Token Interceptor Angular 10

With Great Angular Components Comes Great (Single) Responsibility

Path mapping with Typescript

Learning JavaScript Must know these things

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store