clamping technique

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
mathminmathmax
const min = 0;
const max = 10;
const value = 5;
const result = Math.min(max, Math.max(min, 5));
ready
lodash way
let lower = 0;
let upper = 10;
let number = 5;    
    number = +number;
    lower = +lower;
    upper = +upper;
    lower = lower === lower ? lower : 0;
    upper = upper === upper ? upper : 0;
    if (number === number) {
        number = number <= upper ? number : upper;
        number = number >= lower ? number : lower;
    }
    const result = number;
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.