diff options
Diffstat (limited to 'lib/utils.coffee')
| -rw-r--r-- | lib/utils.coffee | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/utils.coffee b/lib/utils.coffee index 16adc305..a1ed23c2 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -184,6 +184,16 @@ Utils = return true if re.test string false + # Calculate the length of the longest shared prefix of a list of strings. + longestCommonPrefix: (strings) -> + return 0 unless 0 < strings.length + strings.sort (a,b) -> a.length - b.length + [ shortest, strings... ] = strings + for ch, index in shortest.split "" + for str in strings + return index if ch != str[index] + return shortest.length + # Convenience wrapper for setTimeout (with the arguments around the other way). setTimeout: (ms, func) -> setTimeout func, ms |
