Bluethousandand2 Bluethousandand2 - 1 year ago 114
Ruby Question

Assign number to alphabet in array

What I want to do is use an

to turn each letter into its corresponding letter in the alphabet plus nine. I know it's possible to put it against a
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 Source

Here's one way: {|ch| ch.ord - 'A'.ord + 10}

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download