const s = Normalise.MinMax.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.
const s = Normalise.MinMax.stream();
s(5); // 1, because it's the highest seen
// With priming:
const s = Normalise.MinMax.stream({ minDefault:0, maxDefault: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 using the min-max technique.
Adjusts min/max as new values are processed. Return values will be in the range of 0-1 (inclusive).
ixfx Guide on Normalising
Use streamWithContext if you want to be able to check the min/max or reset the normaliser.