Skip to content

Instantly share code, notes, and snippets.

@andersr
Created October 13, 2013 17:41
Show Gist options
  • Save andersr/6965062 to your computer and use it in GitHub Desktop.
Save andersr/6965062 to your computer and use it in GitHub Desktop.
# 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