loading...

re: Daily Challenge #244 - Search for Letters VIEW POST

FULL DISCUSSION
 

Here is a Ruby solution

def change(str)
  result = '0' * 26
  str = str.downcase
  str.each_char do |char|
    result[(char.ord - 97)] = '1' if char.ord.between?(97, 122)
  end
  result
end
 

Ruby can also multiply strings by numbers, which is a bit easier than joining an array:

'0' * 26
#=> "00000000000000000000000000"
 

Thanks Michael, I like that better.

code of conduct - report abuse