Here is a Ruby solution
result = '0' * 26
str = str.downcase
str.each_char do |char|
result[(char.ord - 97)] = '1' if char.ord.between?(97, 122)
Ruby can also multiply strings by numbers, which is a bit easier than joining an array:
'0' * 26
Thanks Michael, I like that better.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.