const similarity = require('./similarity');

/**
 * @param {string} name
 * @param {string[]} nameGroup
 * @returns {string | null}
 */
function similarityGroup(name, nameGroup) {
  let currentName = null;
  let currentDistance = 0;

  nameGroup.forEach((value) => {
    const distance = similarity(value, name);

    if (distance >= 0.25 && distance > currentDistance) {
      currentName = value;
      currentDistance = distance;
    }
  });

  return currentName;
}

module.exports = similarityGroup;
