/**
 * @param {string} nameA
 * @param {string} nameB
 * @returns {number}
 */
function similarity(nameA = '', nameB = '') {
  const lengthA = nameA.length;
  const lengthB = nameB.length;
  const minLength = lengthA > lengthB ? lengthB : lengthA;
  const maxLength = lengthA < lengthB ? lengthB : lengthA;
  let equivalency = 0;

  for (let i = 0; i < minLength; i += 1) {
    if (nameA[i] === nameB[i]) {
      equivalency += 1;
    }
  }

  return equivalency / maxLength;
}

module.exports = similarity;
