Password Verification in Ruby : I've been tasked with a very simple password verification, but for the life of me, I cannot seem to get this right. Here is the task:

> The user sends a numeric password of 6 characters through a form. In
> order to force secure passwords create a validation that the numbers
> cannot consecutively go up or down.

Here is what I have:

    password = '246879'
    new_password = password.split('').map { |s| s.to_i }
    
    new_password.each_with_index do |val, index|
    
      next_element = new_password[index + 1]
      prev_element = new_password[index - 1]
    
      if new_password[index] + 1 == next_element
        puts 'next bad'
        break
      elsif
        new_password[index] - 1 == prev_element
        puts 'prev bad'
        break
      end
    end

The password should fail on the 87 because 7 is one less than 8. Thank you for any help.