From cae1960ca3a5c25d8db458234ac0a6e97ab87ed5 Mon Sep 17 00:00:00 2001 From: Chashmeet Singh Date: Mon, 5 Oct 2015 17:51:23 +0530 Subject: Reverse an array --- ruby.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 7bd28d86..4e8dcc8f 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -168,6 +168,10 @@ array[-1] #=> 5 # With a start index and length array[2, 3] #=> [3, 4, 5] +# Reverse an Array +# array = [1,2,3] +array.reverse #=> [3,2,1] + # Or with a range array[1..3] #=> [2, 3, 4] -- cgit v1.2.3 From 51e3bd21e29ac19884eca57c6f4f1defbd78ea3a Mon Sep 17 00:00:00 2001 From: Chashmeet Singh Date: Mon, 5 Oct 2015 20:22:07 +0530 Subject: Reverse a list --- ruby.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 4e8dcc8f..b6d0e44d 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -169,8 +169,8 @@ array[-1] #=> 5 array[2, 3] #=> [3, 4, 5] # Reverse an Array -# array = [1,2,3] -array.reverse #=> [3,2,1] +a=[1,2,3] +a[::-1] #=> [3,2,1] # Or with a range array[1..3] #=> [2, 3, 4] -- cgit v1.2.3 From 0beb78ac436d232ce73986848f354fc4e7210dfb Mon Sep 17 00:00:00 2001 From: Chashmeet Singh Date: Mon, 5 Oct 2015 20:32:00 +0530 Subject: Reverse an array --- ruby.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index b6d0e44d..8f23b2e6 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -170,7 +170,7 @@ array[2, 3] #=> [3, 4, 5] # Reverse an Array a=[1,2,3] -a[::-1] #=> [3,2,1] +a.reverse! #=> [3,2,1] # Or with a range array[1..3] #=> [2, 3, 4] -- cgit v1.2.3