{"size": 1037, "ext": "js", "max_stars_repo_path": "algorithms/commonCharacters/commonCharacters.js", "max_stars_repo_name": "mbelesiu/algorithms-data-structures", "max_stars_repo_stars_event_min_datetime": "2020-11-16T15:55:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-16T15:55:05.000Z", "max_issues_repo_path": "algorithms/commonCharacters/commonCharacters.js", "max_issues_repo_name": "mbelesiu/algorithms-data-structures", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "algorithms/commonCharacters/commonCharacters.js", "max_forks_repo_name": "mbelesiu/algorithms-data-structures", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.40625, "max_line_length": 95, "alphanum_fraction": 0.6933461909}
/**
 * Write a function `f(a, b)` which takes two strings as arguments and returns a
 * string containing the characters found in both strings (without duplication), in the
 * order that they appeared in `a`. Remember to skip spaces and characters you
 * have already encountered!
 *
 * Example: commonCharacters('acexivou', 'aegihobu')
 * Returns: 'aeiou'
 *
 * Extra credit: Extend your function to handle more than two input strings.
 */



var commonCharacters = function (string1, string2) {
  // TODO: Your code here!
  // create a set from the first string, there by removing any dulplicates
  // navigate thrugh the set, and compare each of the indexs in it to the second, one at a time
  // if a match is found, add that character to the results
  //return the result
  let common = '';
  const unqString = new Set();
  string1 = string1.split('');
  string1.forEach((letter) => unqString.add(letter));
  unqString.forEach((letter) => {
    if (string2.includes(letter)) {
      common += letter;
    }
  })
  return common;
};
