text: const { NotImplementedError } = require('../extensions/index.js');
  
  /**
   * 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,
   * }
   *
   */
  const getDNSStats = (domains) => domains
    .reduce((acc, domain) => {
      domain
        .split('.')
        .reverse()
        .map(elem => '.' + elem)
        .forEach((_, index, array) => {
          const DNS = array.slice(0, index + 1).join('')
          if (acc[DNS]) acc[DNS] += 1
          else acc[DNS] = 1
        })
  
      return acc;
    }, {});
  
  module.exports = {
    getDNSStats
  };
  