Permalink
Browse files

More succinct way to say n in 0 .. 255:

     Math.max   0, n - returns the greater of   0 and n
     Math.min 255, n - returns the smaller of 255 and n

Again had to look at the solutions provided by others.
  • Loading branch information...
1 parent abf141f commit fd8c5bd5bcf8357f4f87c161137a30384bd54884 @j1n3l0 committed Sep 4, 2013
Showing with 1 addition and 2 deletions.
  1. +1 −2 test/codewars-test.coffee
View
3 test/codewars-test.coffee
@@ -30,8 +30,7 @@ describe "RGB To Hex Conversion", ->
solution = (r,g,b) ->
hex_value = "0123456789ABCDEF"
[r,g,b]
- .map((n) -> if n < 0 then 0 else n)
- .map((n) -> if n > 255 then 255 else n)
+ .map((n) -> Math.min 255, Math.max(0, n))
.map((n) -> hex_value[Math.floor(n/16)] + hex_value[n%16])
.join("")

0 comments on commit fd8c5bd

Please sign in to comment.