Skip to content

Commit

Permalink
clamp-left, clamp-right
Browse files Browse the repository at this point in the history
  • Loading branch information
dustingetz committed Dec 21, 2024
1 parent 6e1dbfd commit d226c45
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/contrib/data.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ Qualify a keyword with a namespace. If already qualified, leave untouched. Nil-s
; org.apache.commons.lang3.StringUtils.containsIgnoreCase()
;(defn str-contains-ignore-case [])

(defn clamp [n left right] (min (max n left) right))
(defn clamp-left [n left] (max n left)) ; when under limit, clamp up to larger
(defn clamp-right [n right] (min n right)) ; when exceeding limit, clamp down to smaller
(defn clamp [n left right] (clamp-right (clamp-left n left) right))

(tests
(clamp 51 10 50) := 50
Expand Down

0 comments on commit d226c45

Please sign in to comment.