lib/berkeley_library/util/strings.rb
# Locates the point at which two strings differ
#
# @return [Integer, nil] the index of the first character in either string
#   that differs from the other, or `nil` if the strings are identical,
#   or are not strings
Locates the point at which two strings differ
Locates the point at which two strings differ
def diff_index(s1, s2)
        return unless string_like?(s1, s2)
        shorter, longer = s1.size > s2.size ? [s2, s1] : [s1, s2]
        shorter.chars.each_with_index do |c, i|
          return i if c != longer[i]
        end
        shorter.length if shorter.length < longer.length 
      end
def diff_index ( s1 , s2 ) return unless string_like? ( s1 , s2 ) shorter , longer = s1 . size > s2 . size ? [ s2 , s1 ] : [ s1 , s2 ] shorter . chars . each_with_index do | c , i | return i if c != longer [ i ] end shorter . length if shorter . length < longer . length end
Locates the point at which two strings differ
Locates the point at which two strings differ
# otherwise they're equal
the index of the first character in either string that differs from the other, or `nil` if the strings are identical, or are not strings
the index of the first character in either string that differs from the other or ` nil ` if the strings are identical or are not strings
Integer, nil
s1
<not_specific>
s2
<not_specific>