diff --git a/Ruby/ruby-array-index-i.rb b/Ruby/ruby-array-index-i.rb new file mode 100644 index 00000000..1d9d8e38 --- /dev/null +++ b/Ruby/ruby-array-index-i.rb @@ -0,0 +1,20 @@ +def element_at(arr, index) + # return the element of the Array variable `arr` at the position `index` + # arr.at(index) # or + return arr[index] +end + +def inclusive_range(arr, start_pos, end_pos) + # return the elements of the Array variable `arr` between the start_pos and end_pos (both inclusive) + return arr[start_pos..end_pos] +end + +def non_inclusive_range(arr, start_pos, end_pos) + # return the elements of the Array variable `arr`, start_pos inclusive and end_pos exclusive + return arr[start_pos...end_pos] +end + +def start_and_length(arr, start_pos, length) + # return `length` elements of the Array variable `arr` starting from `start_pos` + return arr[start_pos, length] +end