import {Normalise} from'https://unpkg.com/ixfx/dist/numbers.js' consts = 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, passing in minDefault
and maxDefault primes the normalisation.
consts = Normalise.stream(); s(5); // 1, because it's the highest seen
// With priming: consts = Normalise.stream(0, 10); s(5); // 0.5, because we're expecting range 0-10
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.
Normalises numbers, adjusting min/max as new values are processed. Normalised return values will be in the range of 0-1 (inclusive).
ixfx Guide on Normalising
Example
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, passing in
minDefault
andmaxDefault
primes the normalisation.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.