Redacted - Bonus questions


#1

Hi,

I’m really struggling with the third bonus questions from this section:
“How might you make a new redacted string and save it as a variable, rather than just printing it to the console?”

I have tried a few different ideas but none seem to work. I’ve had a look on the forum but don’t really understand the solutions people have posted there. Would appreciate any help!


#2

Redacted! - Great Work!

Have your program declare an empty array on your output variable.

dup_str = []

Now instead of printing, append to that array, join and reassign back onto that variable and print the final result.

    dup_str << word
  else
    dup_str << 'REDACTED'

and,

dup_str = dup_str.join(' ')
puts dup_str

Extra Study

Come back to this problem when you have picked up some more advanced methods that will allow changes, in place, on the reference string. There’s your variable. If you want to preserve the input text, make a dup or clone of it and work on the clone as your output object.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.