Skip to content

Instantly share code, notes, and snippets.

@shinobcrc
Created June 22, 2016 14:32
Show Gist options
  • Save shinobcrc/3b92cb1719dddb4469be7931bc4d813b to your computer and use it in GitHub Desktop.
Save shinobcrc/3b92cb1719dddb4469be7931bc4d813b to your computer and use it in GitHub Desktop.
Character count and Index locater
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