Check which characters exist in string (Ruby) -


i'm attempting create function detects characters exist in string. function returns 26 character long string. string have 1 or 0 in character's position in string depending on whether character found or not. if b , z found function return

01000000000000000000000001

this have far.

def convert(str)     alpha = ("a".."z").to_a.join     alpha.each_char |i|         num = 0         (str.include? i) ? (alpha[num] = 1) : (alpha[num] = 0)         num =+ 1     end     print ans end convert("a 345 % b ^    xxz") 

however, keep getting error on 5th line:

no implicit conversion of fixnum string (typeerror)

not sure how around this. tips?

you can't assign number string. replace 1 , 0 on line "1" , "0".

also, think mean num += 1 instead of num = +1!


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -