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