leastChars function

List<Map<String, int>> leastChars(
  1. String text, {
  2. bool ignoreSpace = true,
})

Implementation

List<Map<String, int>> leastChars(String text, {bool ignoreSpace = true}) {
  final list = charsRepetition(text,
      sorted: true, order: Order.ascending, ignoreSpace: ignoreSpace);
  late int min;
  bool firstInit = false;
  List<Map<String, int>> result = [];
  for (var word in list.entries) {
    if (!firstInit) {
      min = word.value;
      firstInit = true;
    }

    if (word.value <= min) {
      min = word.value;
      result.add({word.key: word.value});
    }
  }
  return result;
}