# frozen_string_literal: true module GuessHandler def respond_to_guess(game, input, code) validate_guess(input) @result = [] @code_clone = code.clone @numbers = input.split('').map(&:to_i) return 'win' if @numbers == code assess_guess(@code_clone, @numbers) game.attempts[:used] += 1 game.attempts[:used] >= game.attempts[:all] ? 'loss' : @result.delete_if { |value| (1..6).include?(value) }.sort end def assess_guess(code, input) @numbers.each_with_index do |element, index| if element == code[index] code[index] = '+' input[@numbers.index(element)] = '' end end @result = code.each_with_index do |el, index| if @numbers.include?(el) code[index] = '-' input.slice!(@numbers.index(el)) end end end end