Skip to content

Commit

Permalink
Added idiomatic way of dividing array into parts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Toon Willems committed Jun 16, 2011
1 parent 06a5572 commit 9575bb8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/benchmarks/ruby/fold.rb
Expand Up @@ -28,10 +28,10 @@ def fold(filename, max_width)
# Fold a single paragraph to the desired width
def fold_paragraph(paragraph, max_width)
# Gradually build our output
str = paragraph.first
str, *rest = paragraph
width = str.length

paragraph.drop(1).each do |word|
rest.each do |word|
if width + word.length + 1 <= max_width
str << ' ' + word
width += word.length + 1
Expand Down

0 comments on commit 9575bb8

Please sign in to comment.