Skip to content

Instantly share code, notes, and snippets.

@fredyr
Last active December 8, 2015 20: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 fredyr/c14eb7204d14cd119803 to your computer and use it in GitHub Desktop.
Save fredyr/c14eb7204d14cd119803 to your computer and use it in GitHub Desktop.
# center a string s on position c
# cent("0", 5) => " 0 "
# cent("000", 5) => " 000 "
# but we ignore right side spaces
cent = fn(s, c) ->
String.duplicate(" ", div(c - String.length(s), 2)) <> s
end
# piping through partials?
# SAAD PUPPY :'(
12 |> (&String.duplicate("0", &1)).()
IO.puts(Enum.join(
Enum.map([1,3,5,7,9,11],
&(cent.(String.duplicate("0", &1), 15))), "\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment