본문 바로가기

프로그래밍/flutter

겹치지 않는 3개의 메뉴 return

1.returnMenu.dart

//returnMenu
//랜덤하게 겹치지 않는 세개의 메뉴 리턴


List<MenuClass> returnMenu(List<MenuClass> menuList, List<String> cannotEat, budget, howMAnyPeople, hateCategory){
  var menuLength = menuList.length;
  var dump = MenuClass("dump", 1, 1, 1, []);
  var returnList = [dump, dump, dump];
  var cnt = 0;
  while(cnt<3){
    if(menuList[Random().nextInt(menuLength)].isAllergy(cannotEat)
      &&menuList[Random().nextInt(menuLength)].isExpensive(budget)
      &&menuList[Random().nextInt(menuLength)].howMany(howManyPeople)
      &&menuList[Random().nextInt(menuLength)].hateFoodCategory(hateCategory)){
      if((returnList[0]!=menuList[Random().nextInt(menuLength)])
        &&(returnList[1]!=menuList[Random().nextInt(menuLength)])){
        returnList[cnt]=menuList[Random().nextInt(menuLength)];
        cnt++;
      }
    }
  }

  return returnList;
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'프로그래밍 > flutter' 카테고리의 다른 글

flutter Mac에 설치하기  (0) 2022.11.24