{"size": 974, "ext": "js", "max_stars_repo_path": "JavaScript/5-loop.js", "max_stars_repo_name": "rocket111185/Composition", "max_stars_repo_stars_event_min_datetime": "2016-12-14T00:20:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T15:16:52.000Z", "max_issues_repo_path": "JavaScript/5-loop.js", "max_issues_repo_name": "rocket111185/Composition", "max_issues_repo_issues_event_min_datetime": "2018-06-14T10:59:06.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-09T09:21:19.000Z", "max_forks_repo_path": "JavaScript/5-loop.js", "max_forks_repo_name": "rocket111185/Composition", "max_forks_repo_forks_event_min_datetime": "2016-10-05T09:58:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-09T09:23:14.000Z"}
{"max_stars_count": 12, "max_issues_count": 7, "max_forks_count": 79, "avg_line_length": 23.1904761905, "max_line_length": 72, "alphanum_fraction": 0.5646817248}
'use strict';

const compose = (...fns) => x => {
  const last = fns.length - 1;
  let res = x;
  for (let i = last; i >= 0; i--) {
    res = fns[i](res);
  }
  return res;
};

const pipe = (...fns) => x => {
  let res = x;
  for (let i = 0; i < fns.length; i++) {
    res = fns[i](res);
  }
  return res;
};

// Usage

const upperFirst = word => word.charAt(0).toUpperCase() + word.slice(1);
const upperCapital = s => s.split(' ').map(upperFirst).join(' ');
const lower = s => s.toLowerCase();
const trim = s => s.trim();

const s = '   MARCUS AURELIUS   ';
console.log(s);
console.log(`lower('${s}') = '${lower(s)}'`);
console.log(`upperCapital('${s}') = '${upperCapital(s)}'`);

{
  console.log('Use compose');
  const capitalize = compose(upperCapital, lower, trim);
  console.log(`capitalize('${s}') = '${capitalize(s)}'`);
}
{
  console.log('Use pipe');
  const capitalize = pipe(trim, lower, upperCapital);
  console.log(`capitalize('${s}') = '${capitalize(s)}'`);
}
