-
Notifications
You must be signed in to change notification settings - Fork 0
/
array.rb
65 lines (49 loc) · 1.08 KB
/
array.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
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
58
59
60
61
62
63
64
65
# a = [1,2,3,4,5]
# p a.last
# p "------------"
# b = (1..10).to_a
# # p b.shuffle!
# p b.reverse!
# p b.reverse
# p b
# p "------------"
# x = "a".."z"
# p x.to_a
# p "------------"
# p x.to_a.shuffle
# p x.to_a.length
# p "------------"
# arr = a << 10
# p arr
# p a.include?(1)
# p a.append("deepak")
# p a.pop()
# p a
# p "------------"
# p a.join
# p a.join('-')
# p a.join(',')
# para = %w(my name is deepak singh rawat)
# p para
# p "------------"
# para.each do |food|
# print food + " "
# end
# p "------------"
# #in same line
# para.each {|food| print food.capitalize + " "}
# p "------------"
# #print only odd numbers
# zz = (1..100).to_a.shuffle
# p zz
# p "------------"
# # zz.select {|number| print number.odd?}
#short way to print 1 to 10 numbners
a = (1..10).to_a
#Delete element at index of array a, returning that element, or nil if index is out of range
# a.delete_at(2)
# p a
# Drop first n elements from array a and return the rest of the elements in an array
# p a.drop(5)
# Remove the last element from array a and return it, or nil if a is empty
p a.pop(9)