I'd like to point out I tried quite extensively to find a solution for this and the closest I got was this. However I couldn't see how I could use map
to solve my issue here. I'm brand new to Ruby so please bear that in mind.
Here's some code I'm playing with (simplified):
def base_word input
input_char_array = input.split('') # split string to array of chars
@file.split("\n").each do |dict_word|
input_text = input_char_array
dict_word.split('').each do |char|
if input_text.include? char.downcase
input_text.slice!(input_text.index(char))
end
end
end
end
I need to reset the value of input_text
back to the original value of input_char_array
after each cycle, but from what I gather since Ruby is reference-based, the modifications I make with the line input_text.slice!(input_text.index(char))
are reflected back in the original reference, and I end up assigning input_text
to an empty array fairly quickly as a result.
How do I mitigate that? As mentioned I've tried to use .map
but maybe I haven't fully wrapped my head around how I ought to go about it.