<commit_before>import { isArray, isNaN as _isNaN, isNull, isUndefined, map, range as range_ } from 'lodash';
import { Float } from './numbers';

/**
 * Check if array contains crappy values (NaN, undefined, null)
 * @param {Array} arr
 * @return {Boolean} true if has crappy values, false otherwise
 */
export function hasCrappyValues(arr) {
  if (!arr || !isArray(arr) || !arr.length) return true;
  return arr.some((val) => _isNaN(val) || isNull(val) || isUndefined(val));
}

/**
 * turn [min, max] domain into domain of length
 * that matches cardinality of colors array
 * @param {array} domain - [min, max] of x-scale domain
 * @param {number} length - intended length of returned array
 * @returns {array}
 */
export function linspace(domain, length) {
  if (length < 2 || domain.length < 2 || domain[0] === domain[1]) return domain;

  const step = Float.divide(Math.abs(Float.subtract(domain[1], domain[0])), length - 1);
  const [min, max] = domain.sort((a, b) => a - b);

  return map(range_(length), (i) => {
    if (i === length - 1) return max;
    return Float.add(Float.multiply(i, step), min);
  });
}
<commit_msg>fix comment on linspace<commit_after>import { isArray, isNaN as _isNaN, isNull, isUndefined, map, range as range_ } from 'lodash';
import { Float } from './numbers';

/**
 * Check if array contains crappy values (NaN, undefined, null)
 * @param {Array} arr
 * @return {Boolean} true if has crappy values, false otherwise
 */
export function hasCrappyValues(arr) {
  if (!arr || !isArray(arr) || !arr.length) return true;
  return arr.some((val) => _isNaN(val) || isNull(val) || isUndefined(val));
}

/**
 * turn [min, max] domain into array of length
 * @param {array} domain - [min, max]
 * @param {number} length - intended length of returned array
 * @returns {array}
 */
export function linspace(domain, length) {
  if (length < 2 || domain.length < 2 || domain[0] === domain[1]) return domain;

  const step = Float.divide(Math.abs(Float.subtract(domain[1], domain[0])), length - 1);
  const [min, max] = domain.sort((a, b) => a - b);

  return map(range_(length), (i) => {
    if (i === length - 1) return max;
    return Float.add(Float.multiply(i, step), min);
  });
}

{'fraction_non_alphanumeric': 0.16583597643860443, 'fraction_numerical': 0.007249660172179429, 'mean_word_length': 4.064220183486238, 'pattern_counts': {'":': 0, '<': 7, '<?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': '873775', 'n_tokens_mistral': 736, 'n_tokens_neox': 722, 'n_words': 240}