Skip to content

Commit fb597b2

Browse files
committed
Drop a level of indent and clean conditional
1 parent 06218c6 commit fb597b2

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Diff for: chapters/arrays/shuffling-array-elements.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ The following code adds the shuffle function to the Array prototype, which means
7979
you are able to run it on any array you wish, in a much more direct manner.
8080

8181
{% highlight coffeescript %}
82-
do -> Array::shuffle ?= ->
83-
if @length > 1
84-
for i in [@length-1..1]
85-
j = Math.floor Math.random() * (i + 1)
86-
[@[i], @[j]] = [@[j], @[i]]
87-
@
82+
Array::shuffle ?= ->
83+
if @length > 1 then for i in [@length-1..1]
84+
j = Math.floor Math.random() * (i + 1)
85+
[@[i], @[j]] = [@[j], @[i]]
86+
this
8887

8988
[1..9].shuffle()
9089
# => [ 3, 1, 5, 6, 4, 8, 2, 9, 7 ]

0 commit comments

Comments
 (0)