<commit_before>function join(array1, array2, { key, key1, key2, match } = {}) {
  if (!Array.isArray(array1) || !Array.isArray(array2)) {
    return [];
  }

  const { doMatch } = validateOptions({ key, key1, key2, match });

  if (typeof doMatch !== 'function') {
    return [];
  }

  return array1.reduce((prev, cur) => {
    const matches = array2.filter(a2 => doMatch(cur, a2));
    return matches.length === 0 ?
      prev :
      prev.concat(matches.map(m => Object.assign({}, m, cur)))
  }, []);
}

function validateOptions({ key, key1, key2, match }) {
  const k1 = key1 || key;
  const k2 = key2 || key;

  let doMatch = match;
  if (typeof doMatch !== 'function') {
    if (!k1 || !k2) {
      doMatch = undefined;
    }
    doMatch = (a, b) => a[k1] === b[k2] && a[k1] !== undefined;
  }

  return {
    doMatch
  };
}

module.exports = { join };
<commit_msg>Refactor validateOptions function<commit_after>const validateOptions = function ({ key, key1, key2, match }) {
  if (typeof match === 'function') {
    return { doMatch: match };
  }

  const k1 = key1 || key;
  const k2 = key2 || key;

  if (!k1 || !k2) {
    return {};
  }

  return {
    doMatch: (a, b) => a[k1] === b[k2] && a[k1] !== undefined
  };
};

function join(array1, array2, { key, key1, key2, match } = {}) {
  if (!Array.isArray(array1) || !Array.isArray(array2)) {
    return [];
  }

  const { doMatch } = validateOptions({ key, key1, key2, match });

  if (typeof doMatch !== 'function') {
    return [];
  }

  return array1.reduce((prev, cur) => {
    const matches = array2.filter(a2 => doMatch(cur, a2));
    return matches.length === 0 ?
      prev :
      prev.concat(matches.map(m => Object.assign({}, m, cur)))
  }, []);
}


module.exports = { join };

{'fraction_non_alphanumeric': 0.19542857142857142, 'fraction_numerical': 0.027428571428571427, 'mean_word_length': 2.9436936936936937, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1703687', 'n_tokens_mistral': 639, 'n_tokens_neox': 630, 'n_words': 153}