longestCommonPrefix function

  1. @visibleForTesting
String longestCommonPrefix(
  1. String a,
  2. String b
)

Implementation

@visibleForTesting
String longestCommonPrefix(String a, String b) {
  for (var i = 0; i < a.length && i < b.length; i++) {
    if (a[i] != b[i]) {
      return a.substring(0, i);
    }
  }
  if (a.length < b.length) {
    return a;
  } else {
    return b;
  }
}