Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions algorithms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def max(array)
return "No array provided." if array.length == 0
highest = array[0]
array[1..-1].each {|x| highest = x if highest < x }
return highest
end


def middle_element(array)
return "No array provided." if array.length == 0
length = array.sort!.length
p array
p length
if length % 2 == 0
return (array[length/2-1] + array[length/2])/2.0
else
return array[length/2]
end
end

def sum_arrays(array1, array2)
arr = []
l = array1.length
0.upto(l-1) {|x| arr[x] = array1[x]+array2[x]}
return arr
end