Base-16 representation: Difference between revisions

Content added Content deleted
(→‎{{header|JavaScript}}: Added a JavaScript version.)
Line 875: Line 875:
<> show upperLimit
<> show upperLimit
<> ":\n",
<> ":\n",
table " " $ chunksOf 15 xs
table justifyRight " " $ chunksOf 15 xs
]
]


------------------------- DISPLAY ------------------------
------------------------- DISPLAY ------------------------


table :: String -> [[String]] -> String
table ::
(Int -> Char -> String -> String) ->
table gap rows =
String ->
let ws = maximum . fmap length <$> transpose rows
[[String]] ->
pw = printf . flip intercalate ["%", "s"] . show
String
in unlines $ intercalate gap . zipWith pw ws <$> rows</lang>
table alignment gap rows =
unlines $
fmap
( intercalate gap
. zipWith (`alignment` ' ') colWidths
)
rows
where
colWidths = maximum . fmap length <$> transpose rows

justifyRight :: Int -> Char -> String -> String
justifyRight n c = (drop . length) <*> (replicate n c <>)</lang>
{{Out}}
{{Out}}
<pre>301 matches up to 500:
<pre>301 matches up to 500: