Skip to content

Instantly share code, notes, and snippets.

@marcoslhc
Last active April 8, 2017 04:15
Show Gist options
  • Select an option

  • Save marcoslhc/df57757e216705938dc08920a0fbed47 to your computer and use it in GitHub Desktop.

Select an option

Save marcoslhc/df57757e216705938dc08920a0fbed47 to your computer and use it in GitHub Desktop.
filter -> map -> reduce
function filterReduce(predicate) {
return function (accum, value) {
if (predicate(value)) {
return accum.concat(value);
} else {
return accum;
}
};
};
function mapReduce(morphism) {
return function (accum, value) {
return accum.concat(morphism(value));
}
}
ClassList.of([
'btn__background--solarized',
'btn__text--solarized',
'btn__overlay--solarized',
'btn__icon',
'btn__placeholder'
]).reduce(filterReduce(str => /--solarized/.test(str)))
.reduce(mapReduce(str => str.concat('--active')));
// ClassList.of([
// "btn__background--solarized--active",
// "btn__text--solarized--active",
// "btn__overlay--solarized--active"
// ]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment