DEV Community

Discussion on: Daily Challenge #191 - Alphabetical Addition

Collapse
nijeesh4all profile image
Nijeesh Joshy

Ruby

def addLetters(*args)
  sum = args
          .map{ |letter| letter.ord - 96 }
          .sum
  sum  = sum % 26
  sum = 26 if sum == 0
  (sum + 96).chr
end

puts addLetters('a', 'b', 'c')# = 'f'
puts addLetters('a', 'b') #= 'c'
puts addLetters('z') #= 'z'
puts addLetters('z', 'a') #= 'a'
puts addLetters('y', 'c', 'b') #= 'd'
puts addLetters() #= 'z'