re: Daily Challenge #3 - Vowel Counter VIEW POST

FULL DISCUSSION
 
import { compose } from 'crocks';

const toLowerCase = s => s.toLowerCase();
const spread = s => [...s];
const length = xs => xs.length;
const included = xs => x => xs.includes(x);
const filter = p => xs => xs.filter(p);

const charIncludesCount = chars => compose(
  length,
  filter(included(toLowerCase(chars)),
  spread,
  toLowerCase
);

const vowelCount = charIncludesCount ('aeiou');
 

You could replace the import of compose with a tiny implementation of it that looks like this (and could be shortened to one line if you really want to):

const identity = (x) => x;
const compose2 = (f, g) => (x) => f(g(x));
const compose = (...funcs) => funcs.reduce(compose2, identity);
 

Could also

const compose = (...fns) => fns.reduce((f, g) => (...args) => (f(g(...args)));
code of conduct - report abuse