Created
October 13, 2013 17:41
-
-
Save andersr/6965062 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# each | |
def my_each(array) | |
i = 0 | |
until i == array.length do | |
yield(array[i]) | |
i+=1 | |
end | |
array | |
end | |
# collect | |
def my_collect(array) | |
new_array = [] | |
i = 0 | |
until i == array.length do | |
new_array << yield(array[i]) | |
i+=1 | |
end | |
new_array | |
end | |
# select | |
def my_select(array) | |
selection_from_array = [] | |
i = 0 | |
until i == array.length do | |
if yield(array[i]) | |
selection_from_array << array[i] | |
end | |
i+=1 | |
end | |
selection_from_array | |
end | |
# none | |
def my_none?(array) | |
i = 0 | |
until i == array.length do | |
if yield(array[i]) | |
false | |
end | |
i+=1 | |
end | |
true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment