DEV Community

Discussion on: Daily Challenge #3 - Vowel Counter

Collapse
 
wolverineks profile image
Kevin Sullivan
const isIncludedIn = <Data>(collection: Data[]) => (value: Data) =>
  collection.includes(value);
const toChars = (input: string) => [...input];
const length = (xs: any[]) => xs.length;
const keepIf = filter => (xs: any[]) => xs.filter(filter);
const pipe = (...fns: Function[]) =>
  fns.reduce((f, g) => (...args) => g(f(...args)));

const detect = (detectableChars: string[]) =>
  pipe(
    toChars,
    keepIf(isIncludedIn(detectableChars)),
    length,
  );

const VOWELS = {
  LOWERCASE: ["a", "e", "i", "o", "u"],
  UPPERCASE: ["A", "E", "I", "O", "U"],
};
const DETECTABLE_LETTERS = [...VOWELS.LOWERCASE, ...VOWELS.UPPERCASE];
export const vowelCounter = detect(DETECTABLE_LETTERS);