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
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 |
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
## 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 |
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
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 |
NewerOlder