<commit_before>import Math from './math';

export default class Arrays extends Math {
  constructor() {
    super();

    this.first = this.applyValidation.bind(this, this.first, this.validateArgumentIsAnArray, 0)();
    this.tail = this.applyValidation.bind(this, this.tail, this.validateArgumentIsAnArray, 0)();
    this.last = this.applyValidation.bind(this, this.last, this.validateArgumentIsAnArray, 0)();
    this.init = this.applyValidation.bind(this, this.init, this.validateArgumentIsAnArray, 0)();
    this.each = this.applyValidation.bind(this, this.each, this.validateArgumentIsAFunction, 1)();
    this.filter = this.applyValidation.bind(this, this.filter, this.validateArgumentIsAnArray, 0)();
    this.filter = this.applyValidation.bind(this, this.filter, this.validateArgumentIsAFunction, 1)();
    this.maxOfList = this.applyValidation.bind(this, this.maxOfList, this.validateArgumentIsAnArray, 0)();
  }

  first(list) {
    if (!list.length) return undefined;

    return list[0];
  }

  tail(list) {
    if (!list.length) return undefined;
    if (list.length === 1) return [];

    return list.slice(1, list.length);
  }

  last(list) {
    if (!list.length) return undefined;

    return list[list.length - 1];
  }

  init(list) {
    if (!list.length) return undefined;

    return list.slice(0, list.length - 1);
  }

  each(list, iteratee) {
    if (!list.length) return;

    iteratee(list[0]);
    this.each(this.tail(list), iteratee);
  }

  filter(list, iteratee) {
    let result = [];

    this.each(list, (element) => {
      if (iteratee(element)) {
        result.push(element);
      }
    });

    return result;
  }

  maxOfList(list) {
    if (!list.length) return undefined;
    if (list.length === 1) return list[0];

    const maxOfTheEnd = this.maxOfList.bind(this)(this.tail(list));

    return this.max(list[0], maxOfTheEnd);
  }

  maxOccurrence(list) {
    if (!Array.isArray(list)) return undefined;
    if (!list.length) return undefined;
    if (list.length === 1) return list[0];

    let occurrences = [];

    list.map((element) => {
      if (occurrences[element] === undefined) {
        occurrences[element] = 1;
      }

      occurrences[element]++;
    });

    let mostFrenquent;
    let frequency = 0;

    for (let key in occurrences) {
      if (occurrences[key] > frequency) {
        frequency = occurrences[key];
        mostFrenquent = key;
      }
    }

    return mostFrenquent;
  }
};
<commit_msg>Adding validator to the 'maxOccurrence' list parameter<commit_after>import Math from './math';

export default class Arrays extends Math {
  constructor() {
    super();

    this.first = this.applyValidation.bind(this, this.first, this.validateArgumentIsAnArray, 0)();
    this.tail = this.applyValidation.bind(this, this.tail, this.validateArgumentIsAnArray, 0)();
    this.last = this.applyValidation.bind(this, this.last, this.validateArgumentIsAnArray, 0)();
    this.init = this.applyValidation.bind(this, this.init, this.validateArgumentIsAnArray, 0)();
    this.each = this.applyValidation.bind(this, this.each, this.validateArgumentIsAFunction, 1)();
    this.filter = this.applyValidation.bind(this, this.filter, this.validateArgumentIsAnArray, 0)();
    this.filter = this.applyValidation.bind(this, this.filter, this.validateArgumentIsAFunction, 1)();
    this.maxOfList = this.applyValidation.bind(this, this.maxOfList, this.validateArgumentIsAnArray, 0)();
    this.maxOccurrence = this.applyValidation.bind(this, this.maxOccurrence, this.validateArgumentIsAnArray, 0)();
  }

  first(list) {
    if (!list.length) return undefined;

    return list[0];
  }

  tail(list) {
    if (!list.length) return undefined;
    if (list.length === 1) return [];

    return list.slice(1, list.length);
  }

  last(list) {
    if (!list.length) return undefined;

    return list[list.length - 1];
  }

  init(list) {
    if (!list.length) return undefined;

    return list.slice(0, list.length - 1);
  }

  each(list, iteratee) {
    if (!list.length) return;

    iteratee(list[0]);
    this.each(this.tail(list), iteratee);
  }

  filter(list, iteratee) {
    let result = [];

    this.each(list, (element) => {
      if (iteratee(element)) {
        result.push(element);
      }
    });

    return result;
  }

  maxOfList(list) {
    if (!list.length) return undefined;
    if (list.length === 1) return list[0];

    const maxOfTheEnd = this.maxOfList.bind(this)(this.tail(list));

    return this.max(list[0], maxOfTheEnd);
  }

  maxOccurrence(list) {
    if (!list.length) return undefined;
    if (list.length === 1) return list[0];

    let occurrences = [];

    list.map((element) => {
      if (occurrences[element] === undefined) {
        occurrences[element] = 1;
      }

      occurrences[element]++;
    });

    let mostFrenquent;
    let frequency = 0;

    for (let key in occurrences) {
      if (occurrences[key] > frequency) {
        frequency = occurrences[key];
        mostFrenquent = key;
      }
    }

    return mostFrenquent;
  }
};

{'fraction_non_alphanumeric': 0.1461721539071797, 'fraction_numerical': 0.008925029750099168, 'mean_word_length': 3.2413793103448274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '7409780', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1612, 'n_words': 337}