Skip to main content
Switch to consistent semicolon policy - see https://javascript.info/structure
Source Link

Maybe there is a risk that the very same authority which is asking you to count vowels will soon ask you to count consonants, just to have you see how flexible your code is.

So it could be a good idea to start with a function that takes two arguments:

  1. the string under test and
  2. the set of accepted vowels.

Like function countCharsFromVowelSet() in the below code snippet.

Note that deciding what exactly is an acceptable vowel is a language and country dependent decision.

const countCharsFromVowelSet = function(str, vowelSet) {
     let arr   = [...str];
     let count = (arr.filter(c => vowelSet.includes(c))).length;
     return count;
};

/* auxiliary function builder function:  */
const makeCharCounter = function(charSet) {
    return (str => countCharsFromVowelSet(str, charSet));
};

const EnglishVowelList   = "AEIOUaeiou""AEIOUaeiou";
const GermanVowelList    = "AEIOUYÄÖÜaeiouyäöü""AEIOUYÄÖÜaeiouyäöü";

const countEnglishVowels = makeCharCounter(EnglishVowelList);
const countGermanVowels  = makeCharCounter(GermanVowelList);

text1  = "William Shakespeare";
count1 = countEnglishVowels(text1);
text2  = "Die Schöpfung";
count2 = countGermanVowels(text2);

console.log("There are " + count1.toString() + " vowels in: " + text1);
console.log("There are " + count2.toString() + " vowels in: " + text2);

Maybe there is a risk that the very same authority which is asking you to count vowels will soon ask you to count consonants, just to have you see how flexible your code is.

So it could be a good idea to start with a function that takes two arguments:

  1. the string under test and
  2. the set of accepted vowels.

Like function countCharsFromVowelSet() in the below code snippet.

Note that deciding what exactly is an acceptable vowel is a language and country dependent decision.

const countCharsFromVowelSet = function(str, vowelSet) {
     let arr   = [...str];
     let count = (arr.filter(c => vowelSet.includes(c))).length;
     return count;
};

/* auxiliary function builder function:  */
const makeCharCounter = function(charSet) {
    return (str => countCharsFromVowelSet(str, charSet));
};

const EnglishVowelList   = "AEIOUaeiou"
const GermanVowelList    = "AEIOUYÄÖÜaeiouyäöü"

const countEnglishVowels = makeCharCounter(EnglishVowelList);
const countGermanVowels  = makeCharCounter(GermanVowelList);

text1  = "William Shakespeare";
count1 = countEnglishVowels(text1);
text2  = "Die Schöpfung";
count2 = countGermanVowels(text2);

console.log("There are " + count1.toString() + " vowels in: " + text1);
console.log("There are " + count2.toString() + " vowels in: " + text2);

Maybe there is a risk that the very same authority which is asking you to count vowels will soon ask you to count consonants, just to have you see how flexible your code is.

So it could be a good idea to start with a function that takes two arguments:

  1. the string under test and
  2. the set of accepted vowels.

Like function countCharsFromVowelSet() in the below code snippet.

Note that deciding what exactly is an acceptable vowel is a language and country dependent decision.

const countCharsFromVowelSet = function(str, vowelSet) {
     let arr   = [...str];
     let count = (arr.filter(c => vowelSet.includes(c))).length;
     return count;
};

/* auxiliary function builder function:  */
const makeCharCounter = function(charSet) {
    return (str => countCharsFromVowelSet(str, charSet));
};

const EnglishVowelList   = "AEIOUaeiou";
const GermanVowelList    = "AEIOUYÄÖÜaeiouyäöü";

const countEnglishVowels = makeCharCounter(EnglishVowelList);
const countGermanVowels  = makeCharCounter(GermanVowelList);

text1  = "William Shakespeare";
count1 = countEnglishVowels(text1);
text2  = "Die Schöpfung";
count2 = countGermanVowels(text2);

console.log("There are " + count1.toString() + " vowels in: " + text1);
console.log("There are " + count2.toString() + " vowels in: " + text2);
Tweaked source code according to SAM suggestions #2
Source Link

Maybe there is a risk that the very same authority which is asking you to count vowels will soon ask you to count consonants, just to have you see how flexible your code is.

So it could be a good idea to start with a function that takes two arguments:

  1. the string under test and
  2. the set of accepted vowels.

Like function countCharsFromVowelSet() in the below code snippet.

Note that deciding what exactly is an acceptable vowel is a language and country dependent decision.

const countCharsFromVowelSet = function(str, vowelSet) {
         let arr   = [...str]str];
         let count = (arr.filter(c => vowelSet.includes(c))).lengthlength;
         return count;
};

/* auxiliary function builder function:  */
const makeCharCounter = function(charSet) {
    return function(str) {
         var count  ==> countCharsFromVowelSet(str, charSet));
         return count;
    }
};

const EnglishVowelList   = "AEIOUaeiou"
const GermanVowelList    = "AEIOUYÄÖÜaeiouyäöü"

const countEnglishVowels = makeCharCounter(EnglishVowelList);
const countGermanVowels  = makeCharCounter(GermanVowelList);

text1  = "William Shakespeare";
count1 = countEnglishVowels(text1);
text2  = "Die Schöpfung";
count2 = countGermanVowels(text2);

console.log("There are " + count1.toString() + " vowels in: " + text1);
console.log("There are " + count2.toString() + " vowels in: " + text2);

Maybe there is a risk that the very same authority which is asking you to count vowels will soon ask you to count consonants, just to have you see how flexible your code is.

So it could be a good idea to start with a function that takes two arguments:

  1. the string under test and
  2. the set of accepted vowels.

Like function countCharsFromVowelSet() in the below code snippet.

Note that deciding what exactly is an acceptable vowel is a language and country dependent decision.

const countCharsFromVowelSet = function(str, vowelSet) {
         let arr   = [...str]
         let count = (arr.filter(c => vowelSet.includes(c))).length
         return count;
};

/* auxiliary function builder function:  */
const makeCharCounter = function(charSet) {
    return function(str) {
         var count  = countCharsFromVowelSet(str, charSet);
         return count;
    }
};

const EnglishVowelList   = "AEIOUaeiou"
const GermanVowelList    = "AEIOUYÄÖÜaeiouyäöü"

const countEnglishVowels = makeCharCounter(EnglishVowelList);
const countGermanVowels  = makeCharCounter(GermanVowelList);

text1  = "William Shakespeare";
count1 = countEnglishVowels(text1);
text2  = "Die Schöpfung";
count2 = countGermanVowels(text2);

console.log("There are " + count1.toString() + " vowels in: " + text1);
console.log("There are " + count2.toString() + " vowels in: " + text2);

Maybe there is a risk that the very same authority which is asking you to count vowels will soon ask you to count consonants, just to have you see how flexible your code is.

So it could be a good idea to start with a function that takes two arguments:

  1. the string under test and
  2. the set of accepted vowels.

Like function countCharsFromVowelSet() in the below code snippet.

Note that deciding what exactly is an acceptable vowel is a language and country dependent decision.

const countCharsFromVowelSet = function(str, vowelSet) {
     let arr   = [...str];
     let count = (arr.filter(c => vowelSet.includes(c))).length;
     return count;
};

/* auxiliary function builder function:  */
const makeCharCounter = function(charSet) {
    return (str => countCharsFromVowelSet(str, charSet));
};

const EnglishVowelList   = "AEIOUaeiou"
const GermanVowelList    = "AEIOUYÄÖÜaeiouyäöü"

const countEnglishVowels = makeCharCounter(EnglishVowelList);
const countGermanVowels  = makeCharCounter(GermanVowelList);

text1  = "William Shakespeare";
count1 = countEnglishVowels(text1);
text2  = "Die Schöpfung";
count2 = countGermanVowels(text2);

console.log("There are " + count1.toString() + " vowels in: " + text1);
console.log("There are " + count2.toString() + " vowels in: " + text2);
Tweaked source code according to SAM suggestions #1
Source Link

Maybe there is a risk that the very same authority which is asking you to count vowels will soon ask you to count consonants, just to have you see how flexible your code is.

So it could be a good idea to start with a function that takes two arguments:

  1. the string under test and
  2. the set of accepted vowels.

Like function countCharsFromVowelSet() in the below code snippet.

Note that deciding what exactly is an acceptable vowel is a language and country dependent decision.

const countCharsFromVowelSet = function(str, vowelSet) {
         varlet arr   = Array[.from(str)..str]
         varlet count = (arr.filter(c => vowelSet.includes(c))).length
         return count;
};

/* auxiliary function builder function:  */
const makeCharCounter = function(charSet) {
    return function(str) {
         var count  = countCharsFromVowelSet(str, charSet);
         return count;
    }
};

const EnglishVowelList   = "AEIOUaeiou"
const GermanVowelList    = "AEIOUYÄÖÜaeiouyäöü"

const countEnglishVowels = makeCharCounter(EnglishVowelList);
const countGermanVowels  = makeCharCounter(GermanVowelList);

text1  = "William Shakespeare";
count1 = countEnglishVowels(text1);
text2  = "Die Schöpfung";
count2 = countGermanVowels(text2);

console.log("There are " + count1.toString() + " vowels in: " + text1);
console.log("There are " + count2.toString() + " vowels in: " + text2);

Maybe there is a risk that the very same authority which is asking you to count vowels will soon ask you to count consonants, just to have you see how flexible your code is.

So it could be a good idea to start with a function that takes two arguments:

  1. the string under test and
  2. the set of accepted vowels.

Like function countCharsFromVowelSet() in the below code snippet.

Note that deciding what exactly is an acceptable vowel is a language and country dependent decision.

const countCharsFromVowelSet = function(str, vowelSet) {
         var arr   = Array.from(str)
         var count = (arr.filter(c => vowelSet.includes(c))).length
         return count;
};

/* auxiliary function builder function:  */
const makeCharCounter = function(charSet) {
    return function(str) {
         var count  = countCharsFromVowelSet(str, charSet);
         return count;
    }
};

const EnglishVowelList   = "AEIOUaeiou"
const GermanVowelList    = "AEIOUYÄÖÜaeiouyäöü"

const countEnglishVowels = makeCharCounter(EnglishVowelList);
const countGermanVowels  = makeCharCounter(GermanVowelList);

text1  = "William Shakespeare";
count1 = countEnglishVowels(text1);
text2  = "Die Schöpfung";
count2 = countGermanVowels(text2);

console.log("There are " + count1.toString() + " vowels in: " + text1);
console.log("There are " + count2.toString() + " vowels in: " + text2);

Maybe there is a risk that the very same authority which is asking you to count vowels will soon ask you to count consonants, just to have you see how flexible your code is.

So it could be a good idea to start with a function that takes two arguments:

  1. the string under test and
  2. the set of accepted vowels.

Like function countCharsFromVowelSet() in the below code snippet.

Note that deciding what exactly is an acceptable vowel is a language and country dependent decision.

const countCharsFromVowelSet = function(str, vowelSet) {
         let arr   = [...str]
         let count = (arr.filter(c => vowelSet.includes(c))).length
         return count;
};

/* auxiliary function builder function:  */
const makeCharCounter = function(charSet) {
    return function(str) {
         var count  = countCharsFromVowelSet(str, charSet);
         return count;
    }
};

const EnglishVowelList   = "AEIOUaeiou"
const GermanVowelList    = "AEIOUYÄÖÜaeiouyäöü"

const countEnglishVowels = makeCharCounter(EnglishVowelList);
const countGermanVowels  = makeCharCounter(GermanVowelList);

text1  = "William Shakespeare";
count1 = countEnglishVowels(text1);
text2  = "Die Schöpfung";
count2 = countGermanVowels(text2);

console.log("There are " + count1.toString() + " vowels in: " + text1);
console.log("There are " + count2.toString() + " vowels in: " + text2);
use markdown list formatting, inline code format
Source Link
Loading
Fixed typo in vowelSet identifier.
Source Link
Loading
Source Link
Loading