Calculate password strength in Ruby and JavaScript