indexPercentage function

List<IdWithPercentage> indexPercentage(
  1. List<int> ids
)

Takes a list of ids and values takes the count and assigns a percentage based on where they are in list 1,2,3,4 = 25, 50, 75, 100

Implementation

List<IdWithPercentage> indexPercentage(List<int> ids) {
  var value = (100 / ids.length);

  List<IdWithPercentage> result = [];
  for (var i = 0; i < ids.length; ++i) {
    result.add(IdWithPercentage(ids[i], ((i + 1) * value).round()));
  }

  return result;
}