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
Post a Comment