functions/index.js
function filter(data, query) {
  var results = [];
  var push = true;

  // omit every result that doesn't pass _every_ filter
  data.forEach((val) => {
    var push = true;

    // if we fail a filter condition, then don't push
    // check if we're over the max price
    if (query.maxPrice > 0) {
      if (val.price.value > query.maxPrice) {
        push = false;
      }
    }

    // check if the city is included
    if (query.cities.length > 0) {
      if (!query.cities.includes(val.location.city)) {
        push = false;
      }
    }

    // check if the type is anywhere to be found
    var found = false;
    if (query.types.length > 0) {
      query.types.forEach((type) => {
        if (val.types.includes(type)) found = true;
      });
    } else {
      // assume it's found if there's no `query.types` on the request
      found = true;
    }
    if (!found) {
      push = false;
    }

    // if we found something, then push it to the results array
    if (push) {
      results.push(val);
    }
  });

  return results;
}
function filter(data, query) {
  var results = [];
  var push = true;

  // omit every result that doesn't pass _every_ filter
  data.forEach((val) => {
    var push = true;

    // if we fail a filter condition, then don't push
    // check if we're over the max price
    if (query.maxPrice > 0) {
      if (val.price.value > query.maxPrice) {
        push = false;
      }
    }

    // check if the city is included
    if (query.cities.length > 0) {
      if (!query.cities.includes(val.location.city)) {
        push = false;
      }
    }

    // check if the type is anywhere to be found
    var found = false;
    if (query.types.length > 0) {
      query.types.forEach((type) => {
        if (val.types.includes(type)) found = true;
      });
    } else {
      // assume it's found if there's no `query.types` on the request
      found = true;
    }
    if (!found) {
      push = false;
    }

    // if we found something, then push it to the results array
    if (push) {
      results.push(val);
    }
  });

  return results;
}
function filter ( data , query ) { var results = [ ] ; var push = true ; // omit every result that doesn't pass _every_ filter data . forEach ( ( val ) => { var push = true ; // if we fail a filter condition, then don't push // check if we're over the max price if ( query . maxPrice > 0 ) { if ( val . price . value > query . maxPrice ) { push = false ; } } // check if the city is included if ( query . cities . length > 0 ) { if ( ! query . cities . includes ( val . location . city ) ) { push = false ; } } // check if the type is anywhere to be found var found = false ; if ( query . types . length > 0 ) { query . types . forEach ( ( type ) => { if ( val . types . includes ( type ) ) found = true ; } ) ; } else { // assume it's found if there's no `query.types` on the request found = true ; } if ( ! found ) { push = false ; } // if we found something, then push it to the results array if ( push ) { results . push ( val ) ; } } ) ; return results ; }
filter returns the travel data that matches the given query.

@param {Array} data - Array of objects containing the travel data to
filter.
@param {Object} query - An HTTP request query object.
@return {Array} - An array of travelData objects.
filter returns the travel data that matches the given query .