prefix method
Return a string between previousRank
and nextRank
as a condition, both params must be of the same length
Implementation
ResultPrefix prefix(String previousRank, String nextRank) {
var response = '';
// if (previousRank.isEmpty) return '';
// if (nextRank.isEmpty) return '';
for (var i = 0; i < previousRank.length; i++) {
var current = '';
if (nextRank.at(i) == wildcard) {
current = wildcard;
} else if (previousRank.at(i) == wildcard) {
if (nextRank.at(i) == alphabet.first()) {
current = wildcard;
} else {
current = alphabet.between(alphabet.first(), nextRank.at(i));
}
} else {
current = alphabet.between(previousRank.at(i), nextRank.at(i));
}
response += current;
if (current != previousRank.at(i)) {
return ResultPrefix(response: response, hasSuffix: false);
}
}
return ResultPrefix(response: response, hasSuffix: true);
}