var DISCOUNT = [{"depart": 70, "country": 68, "oper": null, "hotel": null, "d1": "2018-02-05", "d2": "2025-03-04", "adult": null, "child": null, "meal": null, "text": "", "discount": {"proc": 0, "rub": 0, "usd": 0, "eur": 0}, "region": null, "subregion": null}, {"depart": 71, "country": 68, "oper": null, "hotel": null, "d1": "2018-02-05", "d2": "2025-03-04", "adult": null, "child": null, "meal": null, "text": "", "discount": {"proc": 0, "rub": 0, "usd": 0, "eur": 0}, "region": null, "subregion": null}, {"depart": 69, "country": 68, "oper": null, "hotel": null, "d1": "2018-02-05", "d2": "2025-03-04", "adult": null, "child": null, "meal": null, "text": "", "discount": {"proc": 0, "rub": 0, "usd": 0, "eur": 0}, "region": null, "subregion": null}, {"depart": 57, "country": 68, "oper": null, "hotel": null, "d1": "2018-02-05", "d2": "2025-03-04", "adult": null, "child": null, "meal": null, "text": "", "discount": {"proc": 0, "rub": 0, "usd": 0, "eur": 0}, "region": null, "subregion": null}, {"depart": 82, "country": 68, "oper": null, "hotel": null, "d1": "2018-02-05", "d2": "2025-03-04", "adult": null, "child": null, "meal": null, "text": "", "discount": {"proc": 0, "rub": 0, "usd": 0, "eur": 0}, "region": null, "subregion": null}]; // function get_discount(depart, country, oper, region, subregion, hotel, adult, child, meal, dt, currency) { function get_discount(params) { var dt_in = moment(params.dt, "DD.MM.YYYY"), hotel_regexp = RegExp('(^|[^\d])' + params.hotel + '([^\d]|$)'), result = {'proc': 0, 'currency_discount': 0, 'text': '', 'active': false}; row = _.find(DISCOUNT, function(item) { return ( (item.depart == null || item.depart == params.depart) && (item.country == null || item.country == params.country) && (item.oper == null || item.oper == params.oper) && // (item.hotel == null || hotel_regexp.test(item.hotel)) && (item.region == null || item.region == params.region) && (item.subregion == null || item.subregion == params.subregion) && (item.adult == null || item.adult == params.adult) && (item.child == null || item.child == params.child) && (item.meal == null || item.meal == params.meal) && (dt_in.isBetween(item.d1, item.d2, 'days', '[]')) ); }); if (row) { if (row.discount.proc > 0) { result.proc = row.discount.proc; } else { result.currency_discount = row.discount[params.currency.toLowerCase()] || 0; } result.text = row.text; result.active = true; } return result; }