Bluethousandand2 Bluethousandand2 - 2 months ago 20
Ruby Question

Assign number to alphabet in array

What I want to do is use an

array.each
to turn each letter into its corresponding letter in the alphabet plus nine. I know it's possible to put it against a
case
going through all 26 letters, but that seems unnecessary.

For example. Say the array is:

["N", "O", "T", "H", "I", "N", "G"]


I want the array to become

["23", "24", "29", "17", "19", "24", "17"]

Answer

Here's one way:

arr.map {|ch| ch.ord - 'A'.ord + 10}