xxxxxxxxxx
// Finding the number of vowels in a string.
// Bir string-dizideki sesli harflerin sayısını bulma.
var str = "Küçük-BÜYÜK sesli harflerden OLUŞAN bir STRİNG cümlesi";
var counter = 0;
str.split("").forEach(element => {
var sesliHarfler = ["A", "E", "I", "İ", "O", "Ö", "U", "Ü", "a", "e", "ı", "i", "o", "ö", "u", "ü"];
var str_1 = (sesliHarfler.includes(element));
if (str_1 == true) {
counter++;
console.log(counter);
};
});
xxxxxxxxxx
const str = "The quick brown fox jumps over a lazy dog";
const vowels = str.match(/[aeiou]/gi);
const consonants = str.match(/[^aeiou]/gi);
vowels.concat([''],consonants).forEach(k => { console.log(k); } );
xxxxxxxxxx
//Example of the solution to finding all the vowels within a string
function countAllTheVowels(string) {
//Finding all of the vowels
const numberOfVowels = string.match(/[aeiou]/gi).length;
//Returning the result
return numberOfVowels;
}
xxxxxxxxxx
function vowelsCount(str){
let count = 0;
let vowels = ["a","e","i","o","u"];
for(let letter of str.toLowerCase()){
for(let v of vowels){
if(letter===v){
count++;
}
}
}
return count;
}
const string = "Hello World. I am a developer";
console.log(vowelsCount(string)); // outcome: 10
xxxxxxxxxx
// BEST and FASTER implementation using regex
const countVowels = (str) => (str.match(/[aeiou]/gi) || []).length
xxxxxxxxxx
function getCount(str) {
return (str.match(/[aeiou]/ig)||[]).length;
}
xxxxxxxxxx
function countVowels(input) {
// const countVowels = new Map();
const vowelCount = {};
// var count =0;
const vowels = ['a', 'e', 'i', 'o', 'u'];
for (let i = 0; i < input.length; i++) {
const char = input[i];
if (vowels.includes(char)) {
if (vowelCount[char]) {
vowelCount[char]++;
} else {
vowelCount[char] = 1;
}
}
}
return vowelCount;
}
console.log(countVowels("anabcod"));
xxxxxxxxxx
//This function accepts a string and
//returns a new string that (matches all vowels) and displays these vowels as such
//Using built in method and RegEx
//Hope this helps:)
function is vowelsOnly(str) {
return str.match(/[aeiou]/ig, '');
}
console.log(vowelsOnly("hello world"));//['e', 'o', 'o']
console.log(vowlesOnly("SHOUT it out"));//['O','U','i','o','u']
xxxxxxxxxx
function countVowel(str) {
// find the count of vowels
const count = str.match(/[e]/gi).length;
return count;
}
// take input
const y = prompt('Enter a name: ');
const result = countVowel(y);
console.log(result);
xxxxxxxxxx
const countVowels = (input) => {
let found = new Object()
input.split("").forEach(char => {
if (char.match(/[aeiou]/gi)) {
const ch = char.toLowerCase()
if (found.hasOwnProperty(ch)) {
found[ch] = found[ch] + 1
} else {
found[ch] = 1
}
}
})
return found
}