function convertIsbn13ToIsbn10(isbn13) {
  if (!isValidIsbn(isbn13)) {
    return null;
  }

  if (isbn13.length === 10) {
    return isbn13;
  }

  const equalPart = isbn13.slice(3, -1);
  const checkSum = equalPart
    .split('')
    .map((d, i) => parseInt(d, 10) * (i + 1))
    .reduce((sum, parcel) => sum + parcel, 0);
  const lastDigit = checkSum % 11;

  return equalPart + (lastDigit === 10 ? 'X' : lastDigit);
}
Convert a valid ISBN-13 string to a obsolete ISBN-10.

@param {string} isbn13 The ISBN-13 representation.
@returns The ISBN-10 representation.