From b4bf8704da701c1804a71227db6c366fd078696d Mon Sep 17 00:00:00 2001 From: Kelly Souza Date: Thu, 27 Apr 2017 07:57:11 -0700 Subject: [PATCH] Whiteboard2 --- whiteboard2.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 whiteboard2.rb diff --git a/whiteboard2.rb b/whiteboard2.rb new file mode 100644 index 0000000..6e19283 --- /dev/null +++ b/whiteboard2.rb @@ -0,0 +1,31 @@ +def mirror(arr) + i = arr.length + arr.length.times do + arr << arr[i-1] + i -= 1 + end + print arr +end + +mirror([1,2,3]) +mirror([1,2,3,4]) +mirror([-1, -2, 3, -4]) +mirror([0]) + + +def switchPairs(array) + i = 0 + (array.length)/2.times do + one = array[i] + two = array[i+1] + array[i] = two + array[i+1] = one + i += 2 + end + puts array +end + + +switchPairs(["four", "score", "and", "seven", "years", "ago"]) +puts "====================" +switchPairs(["four", "score", "and", "seven", "years", "ago", "lincoln"])