Skip to main content
1 of 2
manatwork
  • 20.6k
  • 5
  • 51
  • 81

Ruby, 38 characters

->a,b{i=0;i+=1while a[i]==b[i];a[0,i]}

Sample run:

2.1.5 :001 > ->a,b{i=0;i+=1while a[i]==b[i];a[0,i]}["global" , "glossary"]
 => "glo" 
2.1.5 :002 > ->a,b{i=0;i+=1while a[i]==b[i];a[0,i]}["department" , "depart"]
 => "depart" 
2.1.5 :003 > ->a,b{i=0;i+=1while a[i]==b[i];a[0,i]}["glove", "dove"]
 => "" 
manatwork
  • 20.6k
  • 5
  • 51
  • 81