mode property

num mode

Returns the mode of this list.

If there are multiple modes, this returns the first mode.

Implementation

num get mode {
  num maxValue = 0;
  int maxCount = 0;

  for (var i = 0; i < length; ++i) {
    var count = 0;
    for (var j = 0; j < length; ++j) {
      if (this[j] == this[i]) {
        ++count;
      }
    }

    if (count > maxCount) {
      maxCount = count;
      maxValue = this[i];
    }
  }

  return maxValue;
}