Created
August 12, 2009 15:09
-
-
Save avescodes/166560 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code Golf: Text Area Tag Edition | |
# Ladies and Gentlemen here is the function | |
# Smallest (and least legible) rewrite wins! | |
def size_for_text_area_tag(string, cols = 40) | |
lines = string.split("\n") | |
rows = lines.map(&:length).inject(0) do |sum,len| | |
sum + if len/cols > 0 | |
len/cols | |
else | |
1 | |
end | |
end | |
"#{cols}x#{rows+2}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment