Skip to content

Instantly share code, notes, and snippets.

def onehundred(arr)
result = []
arr.each_with_index do |x,i|
i_of_2nd = arr[i..arr.length].find_index(100-x)
if i_of_2nd
result << [x, 100-x]
arr.delete_at(i_of_2nd)
end
end
return result
@EricDykstra
EricDykstra / review.rb
Last active December 15, 2015 12:19
Phase 1 Assessment Review
## enumerable methods ##
p [1,2,3,4,5].each { |x| x * 2 } == [] #put the output here to make it return true
p [1,2,3,4,5].map { |x| x * 2 } == []
p [1,2,3,4,5].select { |x| x % 2 == 0 } == []
## hashes ##
hash = {1 => 2, [99,99] => "fifty", a: {b:"a"}}
p 2 == hash[1] #example
p "fifty" == hash
p "a" == hash
@EricDykstra
EricDykstra / Shuffler
Created March 13, 2013 02:54
Shuffler
def better_shuffle(array)
shuffled_array = []
until array.length == 0
rand_num = rand(array.length - 1)
shuffled_array << array.delete_at(rand_num)
end
return shuffled_array
end