<commit_before>const specificity = require('specificity')

module.exports = selectors => {
  const totalSelectors = selectors.length
  const identifiersPerSelector = selectors
    .map(selector => specificity.calculate(selector).shift())
    .map(selector => {
      return {
        selector: selector.selector,
        identifiers: selector.parts.length
      }
    })

  const totalIdentifiers = identifiersPerSelector
    .map(selector => selector.identifiers)
    .reduce((prev, curr) => prev + curr, 0)
  const average = totalIdentifiers / totalSelectors

  const top = (count) => {
    const sorter = (a, b) => {
      if (a.identifiers === b.identifiers) {
        return a.selector.localeCompare(b.selector)
      }

      return b.identifiers - a.identifiers
    }

    return identifiersPerSelector
      .sort(sorter)
      .slice(0, count)
  }

  return {
    average,
    top: top(5)
  }
}<commit_msg>Fix test<commit_after>const specificity = require('specificity')

module.exports = selectors => {
  const totalSelectors = selectors.length
  const identifiersPerSelector = selectors
    .map(selector => specificity.calculate(selector).shift())
    .map(selector => {
      return {
        selector: selector.selector,
        identifiers: selector.parts.length
      }
    })

  const totalIdentifiers = identifiersPerSelector
    .map(selector => selector.identifiers)
    .reduce((prev, curr) => prev + curr, 0)
  const average = totalIdentifiers / totalSelectors

  const top = count => {
    const sorter = (a, b) => {
      if (a.identifiers === b.identifiers) {
        return a.selector.localeCompare(b.selector)
      }

      return b.identifiers - a.identifiers
    }

    return identifiersPerSelector
      .sort(sorter)
      .slice(0, count)
  }

  return {
    average,
    top: top(5)
  }
}
{'fraction_non_alphanumeric': 0.11629182665935271, 'fraction_numerical': 0.0032912781130005485, 'mean_word_length': 2.784232365145228, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5270554', 'n_tokens_mistral': 552, 'n_tokens_neox': 532, 'n_words': 115}