{"size": 693, "ext": "js", "max_stars_repo_path": "src/02-common-character-count.js", "max_stars_repo_name": "beeebeep/rs-school-short-track-2021", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/02-common-character-count.js", "max_issues_repo_name": "beeebeep/rs-school-short-track-2021", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/02-common-character-count.js", "max_forks_repo_name": "beeebeep/rs-school-short-track-2021", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.5, "max_line_length": 80, "alphanum_fraction": 0.5786435786}
/**
 * Given two strings, find the number of common characters between them.
 *
 * @param {String} s1
 * @param {String} s2
 * @return {Number}
 *
 * @example
 * For s1 = "aabcc" and s2 = "adcaa", the output should be 3
 * Strings have 3 common characters - 2 "a"s and 1 "c".
 */
function getCommonCharacterCount(s1, s2) {
  let sum = 0;
  const m1 = [...s1].reduce((m, v) => m.set(v, (m.get(v) || 0) + 1), new Map());
  const m2 = [...s2].reduce((m, v) => m.set(v, (m.get(v) || 0) + 1), new Map());
  const entries = new Set([...m1.keys(), ...m2.keys()]);
  entries.forEach((k) => { sum += (Math.min(m1.get(k), m2.get(k))) || 0; });
  return sum;
}

module.exports = getCommonCharacterCount;
