Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tehut Getahun #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions white_board.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require 'pry'


def print_array(array)

string = ""
array.each{|number| string += "#{number},"}
string = "["+ string
string[-1] = "]"
print string

end





def stretch(array)
stretch = []
array.each do |number|
if number % 2 == 0
2.times{stretch << number/2}
else
stretch << number/2 + 1
stretch << number/2
end
end
print stretch

end


def numUnique(array)
hash = {}
array.each_with_index do |num,index|
if array[index] != array[index-1]
hash[num] = 1
else
hash[num] += 1
end
end
return hash.length

end


# I spent an extra two days on this because I lost scope of the problem entirely. I thought I was
#trying to return the array without duplicates and not the length.
def numUnique2(array)
unique = 0
array.each_with_index do |num,index|
if array[index] == array[index+1]
unique = unique
elsif array[index] != array[index+1]
unique += 1
end
end



return unique

end

list = 2,3,3,4,5,6,7,7,8
print numUnique2(list)