14 ms·
If you indent each line by, uh, something (I use 4 spaces), HN gives you code formatting: class Rect(left, top, right, bottom)
by unwind 2y ago
If you indent each line by, uh, something (I use 4 spaces), HN gives you code formatting:
class Rect(left, top, right, bottom)
fun rect_like_to_rect(v):
match v
| Rect(_, _, _, _): v
| {"LT": [l, t], "RB": [r, b]}: Rect(l, t, r, b)
| {"TL": [t, l], "RB": [b, r]}: Rect(l, t, r, b)
rect_like_to_rect({"TL": [0, 2], "RB": [10, 5]})
// ⇒ Rect(0, 2, 10, 5)
rect_like_to_rect({"LT": [0, 2], "RB": [10, 5]})
// ⇒ Rect(2, 0, 5, 10)
Not sure about the typo though, just wanted to make the code readable here since showing off code in the language being talked about is helpful.
- Jtsummers 2y agoTwo spaces are all you need. There are only two formatting rules on HN so it's easy to remember: * around text adds emphasis emphasis. Two spaces before each line creates a code block.