Code Explainers

Code explainers tagged #text-wrapping

ruby
def wrap_text(text, width = 80)
  raise ArgumentError, "width must be positive" unless width.positive?
 
  text.split(/\n/, -1).map do |paragraph|

How greedy text wrapping works in Ruby

string-processing greedy-algorithm text-wrapping
Intermediate 7 steps