Possible Duplicate:
Find common prefix of strings
Let's say I have an array of strings. The array has at least two elements, and possibly more. Each string in the array has at least two characters, and possibly more, and at least the first character of every string is the same.
Given said string array, what's the most efficient way to determine the longest prefix shared across all strings?
For example, given ['cowgirl', 'cowboy']
, the common prefix is cow
. Or, given ['a', 'abs', apples']
, the common prefix is a
.