Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to find vowels in given sting?

I have requirement like if the given string contains vowels it should print the founded vowels , if it does not contain vowels it should print message like no vowels found.

function findVowels(str) {

    const vowels = ['a', 'e', 'i', 'o', 'u'];

    const foundVowels = str.contains(vowels);

    if (foundVowels.length > 0) {
        console.log('Found vowels:', foundVowels.join(', '));
    } else {
        console.log('No vowels found.');
    }
}

const inputString = "Hello, World!";
findVowels(inputString);

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I found one solution for your requirement. You need to modify your code like below.

function findVowels(str) {
    // Convert the string to lowercase to make the check case-insensitive
    str = str.toLowerCase();

    // Define an array of vowels
    const vowels = ['a', 'e', 'i', 'o', 'u'];

    // Filter the characters in the string that are vowels
    const foundVowels = Array.from(str).filter(char => vowels.includes(char));

    if (foundVowels.length > 0) {
        console.log('Found vowels:', foundVowels.join(', '));
    } else {
        console.log('No vowels found.');
    }
}

// Example usage:
const inputString = "Hello, World!";
findVowels(inputString);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading