-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Array basics and fundamentals | ||
|
||
data = [ 1, 2.0, 4.9, "Filly", "Amey" ] | ||
|
||
puts data | ||
|
||
data.each{|x| puts x} | ||
|
||
puts data[3] | ||
|
||
puts data[-2] | ||
|
||
data[0] = "THE MEGA" | ||
|
||
puts data | ||
|
||
# Push operation in array | ||
|
||
data << "Hello World!" | ||
|
||
puts data | ||
|
||
puts data[-1] | ||
|
||
data.pop | ||
|
||
puts data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Array basics and fundamentals | ||
|
||
names = Array.new(6, "Filly...!") | ||
|
||
puts names | ||
|
||
puts "#{names}" | ||
|
||
|
||
digits = Array(0...9) | ||
|
||
puts digits | ||
|
||
|
||
digits = Array(0..9) | ||
|
||
puts digits | ||
|
||
puts digits.at(5) | ||
|
||
|
||
fruits = ["apple", "banana", "pineapple"] | ||
|
||
veggies = ["carrot", "radish", "cabbage"] | ||
|
||
edibles = fruits + veggies | ||
|
||
puts "Yeah, this fruit is included in the list" if fruits.include?("apple") | ||
|
||
puts fruits.first | ||
|
||
puts edibles.first | ||
|
||
puts edibles.last | ||
|
||
puts edibles.first(5) | ||
|
||
puts edibles.reverse | ||
|
||
puts fruits.index("banana") | ||
|
||
newedibles = edibles - fruits | ||
|
||
puts newedibles | ||
|
||
|
||
x = [2, 1, 3, 23, 8] | ||
|
||
puts x.sort | ||
|
||
puts x.sort.reverse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Array basics and fundamentals | ||
|
||
a = ['F', 'i', 'l', 'l', 'y'] | ||
|
||
print a | ||
|
||
print(a[0,5]) | ||
|
||
print(a[-5,5]) | ||
|
||
print(a[0..4]) | ||
|
||
print(a[-5..-1]) | ||
|
||
|
||
b = Array.new(a) | ||
|
||
puts b | ||
|
||
|
||
c= [1, 2, 3, 4] | ||
|
||
a.concat(c) | ||
|
||
print a | ||
|
||
|
||
a.delete("i") | ||
|
||
print a | ||
|
||
|
||
a.delete_at(0) | ||
|
||
print a | ||
|
||
|
||
puts a.size | ||
|
||
|
||
puts a.length | ||
|
||
|
||
puts a.inspect | ||
|
||
|
||
puts a.empty? | ||
|
||
|
||
a.shift | ||
|
||
puts a | ||
|
||
|
||
puts a.equal?(c) | ||
|
||
|
||
p = [1, 1, 2, 2, 3, 3, 4] | ||
|
||
q = [5, 5, 4, 4, 3, 3, 2] | ||
|
||
r = p | q | ||
|
||
puts r | ||
|
||
r = q | p | ||
|
||
puts r | ||
|
||
r = p&q | ||
|
||
puts r | ||
|
||
r = q&p | ||
|
||
puts r |