Skip to content

Commit

Permalink
golden square
Browse files Browse the repository at this point in the history
  • Loading branch information
nagorevalero committed May 12, 2022
1 parent b711e0d commit 67134c0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
1 change: 0 additions & 1 deletion challenges/lib/diary_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def contents

def word_count
word_count_total = @contents.split(" ").count
binding.irb
return word_count_total
end

Expand Down
2 changes: 1 addition & 1 deletion challenges/lib/exersise2_debugging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ def get_most_common_letter(text)
end
counter.delete(" ")
counter_array = counter.to_a.sort_by { |key,value| value }
binding.irb
counter_array.max_by{|key,value| value }[0]

end

puts get_most_common_letter("the roof, the roof, the roof is on fire!")
Expand Down
57 changes: 28 additions & 29 deletions challenges/lib/lettercounter.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
class LetterCounter
def initialize(text)
@text = text
end

def calculate_most_common()
counter = Hash.new(1)
binding.irb
most_common = nil
most_common_count = 1
@text.chars.each do |char|
next unless is_letter?(char)
counter[char] = (counter[char] || 1) + 1
if counter[char] > most_common_count
most_common = char
most_common_count += counter[char]
end
def initialize(text)
@text = text
end

def calculate_most_common
counter = Hash.new(0)
most_common = nil
most_common_count = 1
@text.chars.each do |char|
next unless is_letter?(char)
counter[char] = (counter[char] || 1) + 1
if counter[char] > most_common_count
most_common = char
most_common_count += 1
end
return [most_common_count, most_common]
end

private

def is_letter?(letter)
return letter =~ /[a-z]/i
end
return [most_common_count, most_common]
end

private

def is_letter?(letter)
return letter =~ /[a-z]/i
end

counter = LetterCounter.new("Digital Punk")
p counter.calculate_most_common

# Intended output:
# [2, "i"]
end

counter = LetterCounter.new("Digital Punk")
p counter.calculate_most_common

# Intended output:
# [2, "i"]

0 comments on commit 67134c0

Please sign in to comment.