Pure Recursion Method

by jacobwsmith

JavaScript

var input = ["build"];

var config = {
  "build": ["js", "css", "version-rev"],
  "js": ["lint", "uglify"],
  "css": ["sass", "css-min"]
};

var tasks = getTasks(config, input, []);

// Pure recursion method, yay!
function getTasks(config, input, initial) {
  return input.reduce((prev, next) => {
    if (config[next]) {
      return getTasks(config, config[next], prev);
    } else {
      return prev.concat(next);
    }
  }, initial);
}

console.log(tasks);