Skip to content

Instantly share code, notes, and snippets.

@jdkealy
Last active September 26, 2016 03:31
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 jdkealy/090fd660cee77fcd3226ae0ff3b1af1c to your computer and use it in GitHub Desktop.
Save jdkealy/090fd660cee77fcd3226ae0ff3b1af1c to your computer and use it in GitHub Desktop.
(defn min-max-calc []
(let [mode @rpick/mode ;; a variable that is 0,1,or 2
[min max] (case mode ;; destructuring in action: switch / case returns vector, assigns names min / max same time
0 [180.0 250.0]
1 [250 400 ]
2 [400 650 ]
[180.0 250.0])
width (- ;; actually kinda shitty... i should be passing the width as a param... this funciton
(utils/portal-width) ;; shuoldn't know that there's a div with 30px padding
30)]
(->> (range min max) ;; creates a range [180,181,182]
(reduce (fn [memo item] ;; reduce over the range
(conj memo [(mod width item) item] ) ;; add [mod, range] e.g. [[1,180] [2,181] [10,182]]
) [] )
(sort-by first) ;; sort by the modulus
first ;; get first one... [1,180]
last))) ;; get last in there 180
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment