forked from TheOdinProject/ruby-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
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
2 changed files
with
41 additions
and
27 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 |
---|---|---|
@@ -1,61 +1,75 @@ | ||
def nil_array(number) | ||
# return an array containing `nil` the given number of times | ||
Array.new(number) | ||
end | ||
|
||
def first_element(array) | ||
# return the first element of the array | ||
array[0] | ||
end | ||
|
||
def third_element(array) | ||
# return the third element of the array | ||
array[2] | ||
end | ||
|
||
def last_three_elements(array) | ||
# return the last 3 elements of the array | ||
array.last(3) | ||
end | ||
|
||
def add_element(array) | ||
# add an element (of any value) to the array | ||
array.push(1) | ||
end | ||
|
||
def remove_last_element(array) | ||
# Step 1: remove the last element from the array | ||
array.pop | ||
|
||
# Step 2: return the array (because Step 1 returns the value of the element removed) | ||
array | ||
end | ||
|
||
def remove_first_three_elements(array) | ||
# Step 1: remove the first three elements | ||
array.shift(3) | ||
|
||
# Step 2: return the array (because Step 1 returns the values of the elements removed) | ||
array | ||
end | ||
|
||
def array_concatenation(original, additional) | ||
# return an array adding the original and additional array together | ||
original + additional | ||
end | ||
|
||
def array_difference(original, comparison) | ||
# return an array of elements from the original array that are not in the comparison array | ||
original - comparison | ||
end | ||
|
||
def empty_array?(array) | ||
# return true if the array is empty | ||
array.empty? | ||
end | ||
|
||
def reverse(array) | ||
# return the reverse of the array | ||
array.reverse | ||
end | ||
|
||
def array_length(array) | ||
# return the length of the array | ||
array.size | ||
end | ||
|
||
def include?(array, value) | ||
# return true if the array includes the value | ||
array.include?(value) | ||
end | ||
|
||
def join(array, separator) | ||
# return the result of joining the array with the separator | ||
array.join(separator) | ||
end |
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