/**
 * Aggregate the total votes of multiple candidates in a single contest. The
 * first argument is the summary results for the contest. The second optional
 * argument is an array of candidate IDs that should be included in the
 * aggregation. If you don't provide an array of candidate IDs then all
 * candidates are included in the aggregation.
 *
 * @param {ContestSummaryResults} summary
 *   The summary results of the contest to aggregate
 * @param {CandidateId[]} [candidateIds]
 *   An optional array of specific candidate IDs to include in the aggregation.
 *   If no array is provided then all candidates are included (the default).
 * @returns {number}
 */
const aggregateCandidateVotes = function aggregateCandidateVotes(summary, candidateIds) {
  if (!summary) return undefined;
  const {
    results = []
  } = summary;
  const includeIds = candidateIds && new Set(candidateIds);
  return results.reduce((total, candidate) => {
    if (includeIds && !includeIds.has(candidate.id)) return total;
    return total + candidate.votes;
  }, 0);
};
export default aggregateCandidateVotes;