# frozen_string_literal: true module GuessHandler def respond_to_guess(game, input, code) @result = [] @numbers = input.split('').map(&:to_i) @code_clone = code.clone return 'win' if @numbers == code assess_guess(code, @numbers, '+') assess_guess(@code_clone.sort, @numbers.sort, '-') game.attempts[:available] -= 1 game.attempts[:used] += 1 game.attempts[:available].zero? ? 'loss' : @result.sort end def assess_guess(code, input, method) input.each_with_index do |element, index| if element == code[index] @result << method @code_clone[index] = 7 end end end end