Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def reject(array)
- reject_array = []
- i = 0
- j = 0
- while i < array.length
- if !yield(array[i])
- reject_array[j] = array[i]
- j += 1
- end
- i += 1
- end
- reject_array
- end
- returns array of elements for which block returns false
- def calculate
- calculation = yield
- end
- calculate { 2 + 2 }
- # => 4
- calculate { 3 * 4 }
- # => 12
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement