79333183

Date: 2025-01-06 13:31:39
Score: 0.5
Natty:
Report link

I updated my code this way; I think it's better than the previous version.

List<Model> findAndOperate({
  required double value,
  required Operations operations,
  required List<Model> mainList,
  required List<Model> selectedList,
}) {
  for (final item in mainList) {
    if (selectedList.contains(item)) {
      final itemIndex = mainList.indexOf(item);
      final changeItem = switch (operations) {
        Operations.PLUS => item.copyWith(price: item.price + value),
        Operations.MULTIPLICATION => item.copyWith(price: item.price * value)
      };
      mainList[itemIndex] = changeItem;
    }
  }
  return mainList;
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Kaan