This file contains hidden or 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 sum(array) | |
return array.inject(:+) | |
end |
This file contains hidden or 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 max_num_char_str(string) | |
split_string = string.split("") | |
count_hash = Hash.new(0) | |
split_string.each do |c| | |
count_hash[c] += 1 unless c == " " | |
end | |
count_hash.max_by { | c, n | n }.join | |
end | |
puts max_num_char_str("lots of sss to show") |
This file contains hidden or 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 reverse_string(string) | |
split_string = string.split("") | |
split_string.reduce([]) { |a, b| a.unshift(b) }.join | |
#reversed = [] | |
#string.size.times { reversed << split_string.pop} | |
#reversed.join | |
end | |
puts reverse_string("codelabs") |
NewerOlder