const pathIterations = ({
  threshold,
  base,
  undecideds
}) => {
  if (base >= threshold) return 1;
  if (undecideds.length < 1) return 0;
  const withBestWin = pathIterations({
    threshold,
    base: base + undecideds[0],
    undecideds: undecideds.slice(1)
  });
  const withoutBestWin = pathIterations({
    threshold,
    base,
    undecideds: undecideds.slice(1)
  });
  return withBestWin + withoutBestWin;
};
const waysToWin = ({
  threshold,
  base,
  undecideds
}) => {
  const orderedVotes = undecideds.slice().sort((a, b) => b - a);
  return pathIterations({
    threshold,
    base,
    undecideds: orderedVotes
  });
};
const getPathCounts = function getPathCounts(opts) {
  const {
    unsetElectorCounts,
    goal,
    assigned
  } = opts;
  return {
    dem: waysToWin({
      threshold: goal,
      base: assigned.dem,
      undecideds: unsetElectorCounts
    }),
    gop: waysToWin({
      threshold: goal,
      base: assigned.gop,
      undecideds: unsetElectorCounts
    })
  };
};
export default getPathCounts;