Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Last active July 17, 2019 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomhodgins/3955ee9fb8dd28d94999f1a396646cc5 to your computer and use it in GitHub Desktop.
Save tomhodgins/3955ee9fb8dd28d94999f1a396646cc5 to your computer and use it in GitHub Desktop.
Clamped Number Formatting Bikeshed

Let's say I have a concept of a set of three numbers:

  • a minimum number the computed value can't drop below
  • a middle number that's a scaling factor we'll use to compute a value
  • a maximum number the computed value can't exceed

There are a few ways a set of numbers like this can be expressed:

  • as a space-separated list:
10 20 30
  • as a colon-separated list:
10:20:30
  • as a comma-separated list:
10, 20, 30
  • as a symbolic expression
(10 20 30)
  • as an array (JSON shown):
[10, 20, 30]
  • as an object (JSON shown):
{
  "min": 10,
  "mid": 20,
  "max": 30
}
  • as digits embedded in a string of text:
Never below 10, try to scale to 20%, but never exceed 30
  • as numbers with < and > (or and ):
10 < 20 > 30

…but what else could work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment