re: Daily Challenge #110 - Love VS. Friendship VIEW POST

FULL DISCUSSION
 

Ruby:

def words_to_marks(word)
  word.chars.sum { |c| c.ord - 96 }
end

For fun a second version that builds a lookup table with an endless range (introduced in Ruby 2.6):

ALPHABET = ('a'..'z').zip(1..).to_h

def words_to_marks(word)
  word.chars.sum { |c| ALPHABET.fetch(c, 0) }
end
code of conduct - report abuse