src/stats/frequencies.js
function relativeFrequencies(sequence) {
  let index,
      length;

  // Handling the object polymorphism
  if (typeof sequence === 'object' && !Array.isArray(sequence)) {
    index = sequence;
    length = 0;

    for (const k in index)
      length += index[k];
  }
  else {
    length = sequence.length;
    index = frequencies(sequence);
  }

  const relativeIndex = {};

  for (const k in index)
    relativeIndex[k] = index[k] / length;

  return relativeIndex;
}
function relativeFrequencies(sequence) {
  let index,
      length;

  // Handling the object polymorphism
  if (typeof sequence === 'object' && !Array.isArray(sequence)) {
    index = sequence;
    length = 0;

    for (const k in index)
      length += index[k];
  }
  else {
    length = sequence.length;
    index = frequencies(sequence);
  }

  const relativeIndex = {};

  for (const k in index)
    relativeIndex[k] = index[k] / length;

  return relativeIndex;
}
function relativeFrequencies ( sequence ) { let index , length ; // Handling the object polymorphism if ( typeof sequence === 'object' && ! Array . isArray ( sequence ) ) { index = sequence ; length = 0 ; for ( const k in index ) length += index [ k ] ; } else { length = sequence . length ; index = frequencies ( sequence ) ; } const relativeIndex = { } ; for ( const k in index ) relativeIndex [ k ] = index [ k ] / length ; return relativeIndex ; }
Relative version of the `frequencies` function.

@param  {mixed}  sequence - The sequence to process. If an object is passed
the function will assume it's representing
absolute frequencies.
@return {object}          - A dict of the sequence's relative frequencies.

@example
// frequencies([1, 1, 2, 3, 3, 3]) => {1: ~0.33, 2: ~0.16, 3: 0.5}
// frequencies('test') => {t: 0.5, e: 0.25, s: 0.25}
Relative version of the frequencies function .