How to remove letters from a word? [closed]

1

For example, I have the following word "ASTRONAUTA", and I want to show it in an alert, it should always show the first letter of the word followed by the next vowel, it should be like this="AO", nose if I do not I explain, it would have to be used for any word, I put another one of example "GEOGRAPHY" it would have to be shown like this="GE" always leaving the first letter and then the nearest vowel. What function would it serve?

    
asked by A.Rafa 19.10.2017 в 07:05
source

1 answer

1

You can take the first letter of the word considering as if it were a Array , then you can go through the word from the position 1 and find the first match that there is with a vowel, and here the example:

function myWord(word) {

    var custom=word[0];

    for (var i=1; i < word.length; i++) {
        var letter = word[i];
        if (/[aeiou]/i.test(letter)) {
             custom+=letter;
             break;
        }
    }

    return custom;
}

myWord('Esternocleidomastoideo'); //Ee

You can also choose to use .toUpperCase() when you return the variable custom so that the two letters returned to you are uppercase .

    
answered by 19.10.2017 / 08:02
source