-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathruby_array.rb
More file actions
57 lines (44 loc) · 923 Bytes
/
ruby_array.rb
File metadata and controls
57 lines (44 loc) · 923 Bytes
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
things = [ 'john', 'jane', :happy, nil, false, {}, [] ]
p things
p things.class
p things.length
p things[3]
p things[-1]
p things[0]
iterations = things.length
iterations.times do |integer|
p things[integer]
end
iterations.times do |integer|
index_position = things.length - integer - 1
p things[index_position]
end
people = ['jane', 'john', 'jim', 'jenny']
people.each do |person|
p "this person's name #{person}"
end
other_people = people.each do |person|
p person.reverse
end
p other_people
p people == other_people
scrambled_people = people.map do |person|
person.reverse
end
p scrambled_people
p people == scrambled_people
def create_funny_sentence(people)
people.inject('') do |sentence, person|
sentence << " look at #{person} go,"
sentence
end
end
p people
p people.pop
p people
p people.push('jonathon')
p people
p people.shift()
p people
p people.unshift('jennifer')
p people