Skip to content

Commit 580d3a9

Browse files
author
David Brady
committed
Added map version to string/repeating
1 parent b58c79c commit 580d3a9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

chapters/strings/repeating.textile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ You want to repeat a string.
1010

1111
h2. Solution
1212

13-
Use a list comprehension that ignores the list:
13+
Use a map or a list comprehension, and flatten it:
1414

1515
{% highlight coffeescript %}
16-
# repeat 'foo' 10 times
1716
('foo' for dummy in [1..10]).join ''
1817
# => "foofoofoofoofoofoofoofoofoofoo"
18+
19+
([1..10].map (x) -> 'foo').join ''
20+
# => "foofoofoofoofoofoofoofoofoofoo"
1921
{% endhighlight %}
2022

2123
Or a simple (but stateful) loop:

0 commit comments

Comments
 (0)