score:0

interface Item {
    value: string;
}

interface ResortResult {
    available: {roomType: string}[][];
    activities: string[];
    propertyCode: string;
    city: string;
}

interface SelectedFilters {
    room: Item[];
    activity: Item[];
    area: string[];
}

 function filter(resortList: ResortResult[], selectedFilters: SelectedFilters) {
    return resortList
      .filter(resort => {
        let roomTypes = resort.available.flat().map(room => room.roomType);
        let activities = resort.activities;
        let hasRoomType = selectedFilters["room"].some(
          (rt) => roomTypes.indexOf(rt.value) > -1
        );
        let hasActivity = selectedFilters["activity"].some(
          (act) => ((activities.indexOf(act.value)) > -1)
        );
        return !(
          (selectedFilters["area"].length === 0 ||
            selectedFilters["area"].indexOf(resort.city) > -1) &&
          // (selectedFilters["views"].length === 0 ||
          //   selectedFilters["views"].indexOf(resort.city) > -1) &&
          (selectedFilters["activity"].length === 0 || hasActivity) &&
          (selectedFilters["room"].length === 0 || hasRoomType)
        );
      })
      .map(resort => {
        return resort.propertyCode;
      });
  }

Related Query

More Query from same tag