I'm a ruby beginner and would like some help!
Let's say we have the following array:
codes = [65, 66, 67, 68, 70, 84]
What ruby code do we have to call, to change this array into ["A", "B", "C", "D", "E", "F"]
?
I want to use the chr method
I'm a ruby beginner and would like some help!
Let's say we have the following array:
codes = [65, 66, 67, 68, 70, 84]
What ruby code do we have to call, to change this array into ["A", "B", "C", "D", "E", "F"]
?
I want to use the chr method
You want Array#map.
[65, 66, 67, 68, 70, 84].map { |number| number.chr }
=> ["A", "B", "C", "D", "F", "T"]
And it's more idiomatic to use Symbol#to_proc:
[65, 66, 67, 68, 70, 84].map(&:chr)
=> ["A", "B", "C", "D", "F", "T"]