<commit_before>// =============================================================================
// Core.js | Utilities
// (c) Mathigon
// =============================================================================



/**
 * Empty Function.
 */
export function noop() {}


/**
 * Creates a random UID string of a given length.
 * @param {?number} n
 * @returns {string}
 */
export function uid(n = 10) {
  return Math.random().toString(36).substr(2, n);
}


/**
 * If obj is a function, it evaluates it with a given set of attributes.
 * Otherwise it just returns obj directly.
 * @param {Function|*} obj
 * @param {...*} args
 * @returns {*}
 */
export function run(obj, ...args) {
  if (obj instanceof Function) return obj(...args);
  return obj;
}


/**
 * Checks if x is strictly equal to any one of the following arguments
 * @param {*} x
 * @param {...*} values
 * @returns {boolean}
 */
export function isOneOf(x, ...values) {
  for (let v of values) {
    if (x === v) return true;
  }
  return false;
}


/**
 * Merges multiple objects into the first one.
 * @param {Object} first
 * @param {...Object} others
 */
export function extend(first, ...others) {
  for (let obj of others) {
    for (let key in obj) {
      if (obj.hasOwnProperty(key)) first[key] = obj[key];
    }
  }
}


/**
 * Deep extends obj1 using th
 * @param obj1
 * @param obj2
 */
export function deepExtend(obj1, obj2) {
  for (let i of Object.keys(obj2)) {
    if (i in obj1 && Array.isArray(obj1[i]) && Array.isArray(obj2[i])) {
      obj1[i] = obj1[i].concat(obj2[i]);
    } else if (i in obj1 && obj1[i] instanceof Object &&
                            obj2[i] instanceof Object) {
      deepExtend(obj1[i], obj2[i]);
    } else {
      obj1[i] = obj2[i];
    }
  }
}


/**
 * Bounds a number between a lower and an upper limit.
 * @param {number} x
 * @param {number} min
 * @param {number} max
 * @returns {number}
 */
export function clamp(x, min = -Infinity, max = Infinity) {
  return Math.min(max, Math.max(min, x));
}


/**
 * Checks if a number is in between two limits.
 * @param {number} x
 * @param {number} a
 * @param {number} b
 * @returns {boolean}
 */
export function isBetween(x, a, b) {
  return x >= a && x <= b;
}


/**
 * Checks the average speed of a function by running it n times.
 * @param {Function} fn
 * @param {?number} n
 * @returns {number}
 */
export function performance(fn, n = 100) {
  window.performance.clearMarks();
  window.performance.clearMeasures();

  window.performance.mark('start');
  for (let i=0; i<n; ++i) fn();
  window.performance.mark('end');

  window.performance.measure('time', 'start', 'end');
  let t = window.performance.getEntriesByName('time')[0].duration;
  return t/n;
}


/**
 * Squares a number.
 * @param {number} x
 * @returns {number}
 */
export function square(x) {<commit_msg>Change isBetween checking to strict<commit_after>// =============================================================================
// Core.js | Utilities
// (c) Mathigon
// =============================================================================



/**
 * Empty Function.
 */
export function noop() {}


/**
 * Creates a random UID string of a given length.
 * @param {?number} n
 * @returns {string}
 */
export function uid(n = 10) {
  return Math.random().toString(36).substr(2, n);
}


/**
 * If obj is a function, it evaluates it with a given set of attributes.
 * Otherwise it just returns obj directly.
 * @param {Function|*} obj
 * @param {...*} args
 * @returns {*}
 */
export function run(obj, ...args) {
  if (obj instanceof Function) return obj(...args);
  return obj;
}


/**
 * Checks if x is strictly equal to any one of the following arguments
 * @param {*} x
 * @param {...*} values
 * @returns {boolean}
 */
export function isOneOf(x, ...values) {
  for (let v of values) {
    if (x === v) return true;
  }
  return false;
}


/**
 * Merges multiple objects into the first one.
 * @param {Object} first
 * @param {...Object} others
 */
export function extend(first, ...others) {
  for (let obj of others) {
    for (let key in obj) {
      if (obj.hasOwnProperty(key)) first[key] = obj[key];
    }
  }
}


/**
 * Deep extends obj1 using th
 * @param obj1
 * @param obj2
 */
export function deepExtend(obj1, obj2) {
  for (let i of Object.keys(obj2)) {
    if (i in obj1 && Array.isArray(obj1[i]) && Array.isArray(obj2[i])) {
      obj1[i] = obj1[i].concat(obj2[i]);
    } else if (i in obj1 && obj1[i] instanceof Object &&
                            obj2[i] instanceof Object) {
      deepExtend(obj1[i], obj2[i]);
    } else {
      obj1[i] = obj2[i];
    }
  }
}


/**
 * Bounds a number between a lower and an upper limit.
 * @param {number} x
 * @param {number} min
 * @param {number} max
 * @returns {number}
 */
export function clamp(x, min = -Infinity, max = Infinity) {
  return Math.min(max, Math.max(min, x));
}


/**
 * Checks if a number is in between two limits.
 * @param {number} x
 * @param {number} a
 * @param {number} b
 * @returns {boolean}
 */
export function isBetween(x, a, b) {
  if (a > b) return x > b && x < a;
  return x > a && x < b;
}


/**
 * Checks the average speed of a function by running it n times.
 * @param {Function} fn
 * @param {?number} n
 * @returns {number}
 */
export function performance(fn, n = 100) {
  window.performance.clearMarks();
  window.performance.clearMeasures();

  window.performance.mark('start');
  for (let i=0; i<n; ++i) fn();
  window.performance.mark('end');

  window.performance.measure('time', 'start', 'end');
  let t = window.performance.getEntriesByName('time')[0].duration;
  return t/n;
}


/**
 * Squares a number.
 * @param {number} x
 * @returns {number}
 */
export function square(x) {
{'fraction_non_alphanumeric': 0.2130115424973767, 'fraction_numerical': 0.010143406785589367, 'mean_word_length': 3.1532316630355846, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, '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': '7510626', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1852, 'n_words': 598}