-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrays.rb
28 lines (21 loc) · 1.03 KB
/
arrays.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
crystal_types = ["Turquoise", "Citrine", "Onyx", "Amethyst"]
favorite_numbers = [777, 9, 18, 100]
soda_prices = [1.11, 2.22, 3.33, 4.44]
im_always_right = [false, false, false, false]
#Push method add two more elements at the end of the array.
crystal_types.push("Obsidian", "Jasper")
p crystal_types
#Pop method will remove the element stored at index 2 from the array.
favorite_numbers.pop
p favorite_numbers
#Shift method will remove the first element from the array.
soda_prices.shift
p soda_prices
#Unshift method will add two elements to the begining of the array.
im_always_right.unshift(true, true)
p im_always_right
#index positions is the position of a specific element stored in an array. One thing to remember is that index position starts at 0.
#For example, in my array, crystal_types = ["Turquoise", "Citrine", "Onyx", "Amethyst"], Turquoise has an index position of 0. While Citrine has an index position of 1
#Reverse! method will reverse the index position order of the array.
favorite_numbers.reverse!
p favorite_numbers