text: /**
   * Given an array of domains, return the object with the appearances of the DNS.
   *
   * @param {Array} domains
   * @return {Object}
   *
   * @example
   * domains = [
   *  'code.yandex.ru',
   *  'music.yandex.ru',
   *  'yandex.ru'
   * ]
   *
   * The result should be the following:
   * {
   *   '.ru': 3,
   *   '.ru.yandex': 3,
   *   '.ru.yandex.code': 1,
   *   '.ru.yandex.music': 1,
   * }
   *
   */
  function getDNSStats(domains) {
    const regexpStart = /\w+(?=\.)/g;
    const regexpBody = /\.\w+/g;
    const map = {};
  
    for (let n = 0; n < domains.length; n++) {
      const arrDomains = domains[n].match(regexpBody).reverse();
      const strStart = domains[n].match(regexpStart)[0];
      /* add to array the begining of the string */
      arrDomains.push(`.${strStart}`);
  
      for (let i = 1; i <= arrDomains.length; i++) {
        const name = arrDomains.slice(0, i).join('');
  
        if (map[name]) {
          map[name]++;
        } else {
          map[name] = 1;
        }
      }
    }
    return map;
  }
  // let domains = ['code.yandex.ru', 'music.yandex.ru', 'yandex.ru'];
  // console.dir(getDNSStats(domains));
  module.exports = getDNSStats;
  