Clamp number

    0

    0

    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
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.