Clamp number



    Giovanny Gongora

    Codiga's TypeScript Recipes

    Clamps num within the inclusive range specified by the boundary values a and b.

    const clampNumber = (num: number, a: number, b: number) =>
      Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.