Created
June 22, 2016 14:32
-
-
Save shinobcrc/3b92cb1719dddb4469be7931bc4d813b to your computer and use it in GitHub Desktop.
Character count and Index locater
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 count_letters(list) | |
letters = Hash.new(0) | |
list.each do |word| | |
word.split('').each { |letter| letters[letter] += 1 } | |
end | |
letters | |
end | |
my_array = ['lighthouse', 'in', 'the', 'house'] | |
puts count_letters(my_array) | |
def find_words(list) | |
list.each_with_index{|value,index| puts "#{value} item is #{index} in the array"} | |
end | |
puts find_words(my_array) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment