• Normalises numbers, adjusting min/max as new values are processed. Normalised return values will be in the range of 0-1 (inclusive).

    Read more in the docs

    Parameters

    • Optional minDefault: number
    • Optional maxDefault: number

    Returns ((v) => number)

      • (v): number
      • Parameters

        • v: number

        Returns number

    Example

    import {Normalise} from 'https://unpkg.com/ixfx/dist/data.js'
    const s = Normalise.stream();
    s(2); // 1 (because 2 is highest seen)
    s(1); // 0 (because 1 is the lowest so far)
    s(1.5); // 0.5 (50% of range 1-2)
    s(0.5); // 0 (because it's the new lowest)

    Since normalisation is being adjusted as new min/max are encountered, it might be that value normalised to 1 at one time is different to what normalises to 1 at a later time.

    If you already know what to expect of the number range, passingin minDefault and maxDefault primes the normalisation.

    const s = Normalise.stream();
    s(5); // 1, because it's the highest seen

    // With priming:
    const s = Normalise.stream(0, 10);
    s(5); // 0.5, because we're expecting range 0-10

    Note that if a value exceeds the default range, normalisation adjusts. Errors are thrown if min/max defaults are NaN or if one attempts to normalise NaN.