Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- beers.sort((first, second) => {
- if (queryParams.sorting === 'дороже') {
- const firstBeerLittreMaxPrice = Math.max.apply(Math, first.products.map((p) => {
- return Math.round(10.0 * p.price / p.boxingVolume) / 10.0;
- }));
- const secondBeerLittreMaxPrice = Math.max.apply(Math, second.products.map((p) => {
- return Math.round(10.0 * p.price / p.boxingVolume) / 10.0;
- }));
- if (firstBeerLittreMaxPrice < secondBeerLittreMaxPrice) return 1;
- if (firstBeerLittreMaxPrice > secondBeerLittreMaxPrice) return -1;
- if (firstBeerLittreMaxPrice == secondBeerLittreMaxPrice) return 0;
- } else if (queryParams.sorting === 'дешевле') {
- const firstBeerLittreMinPrice = Math.min.apply(Math, first.products.map((p) => {
- return Math.round(10.0 * p.price / p.boxingVolume) / 10.0;
- }));
- const secondBeerLittreMinPrice = Math.min.apply(Math, second.products.map((p) => {
- return Math.round(10.0 * p.price / p.boxingVolume) / 10.0;
- }));
- if (firstBeerLittreMinPrice > secondBeerLittreMinPrice) return 1;
- if (firstBeerLittreMinPrice < secondBeerLittreMinPrice) return -1;
- if (firstBeerLittreMinPrice == secondBeerLittreMinPrice) return 0;
- } else if (queryParams.sorting === 'новинки') {
- if (first.timestamp < second.timestamp) return 1;
- if (first.timestamp > second.timestamp) return -1;
- if (first.timestamp == second.timestamp) return 0;
- }
- });
Add Comment
Please, Sign In to add comment