export const combinations = (...arg) => {
  const result = [];
  const max = arg.length - 1;

  const helper = (arr, i) => {
    for (let j = 0, l = arg[i].length; j < l; j += 1) {
      const a = arr.slice(0); // clone arr
      a.push(arg[i][j]);
      if (i === max) {
        result.push(a);
      } else {
        helper(a, i + 1);
      }
    }
  };

  helper([], 0);
  return result;
};

export default combinations;
