{"size": 839, "ext": "js", "max_stars_repo_path": "src/st-dns-stats.js", "max_stars_repo_name": "ShustovaElena/basic-js", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/st-dns-stats.js", "max_issues_repo_name": "ShustovaElena/basic-js", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/st-dns-stats.js", "max_forks_repo_name": "ShustovaElena/basic-js", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.4634146341, "max_line_length": 80, "alphanum_fraction": 0.5303933254}
import { NotImplementedError } from '../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,
 * }
 *
 */
export default function getDNSStats(domains) {
  let obj = {};
  for (let i = 0; i < domains.length; i++) {
    let array = domains[i].split('.');
    array.reverse();
    for (let j = 0; j < array.length; j++) {
      let domain = '.' + array.slice(0, j + 1).join('.');
      if (domain in obj) {
        obj[domain]++;
      } else {
        obj[domain] = 1;
      }
    }
  }
  return obj;
}
