Guest User

Untitled

a guest
May 21st, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. beers.sort((first, second) => {
  2. if (queryParams.sorting === 'дороже') {
  3. const firstBeerLittreMaxPrice = Math.max.apply(Math, first.products.map((p) => {
  4. return Math.round(10.0 * p.price / p.boxingVolume) / 10.0;
  5. }));
  6. const secondBeerLittreMaxPrice = Math.max.apply(Math, second.products.map((p) => {
  7. return Math.round(10.0 * p.price / p.boxingVolume) / 10.0;
  8. }));
  9. if (firstBeerLittreMaxPrice < secondBeerLittreMaxPrice) return 1;
  10. if (firstBeerLittreMaxPrice > secondBeerLittreMaxPrice) return -1;
  11. if (firstBeerLittreMaxPrice == secondBeerLittreMaxPrice) return 0;
  12. } else if (queryParams.sorting === 'дешевле') {
  13. const firstBeerLittreMinPrice = Math.min.apply(Math, first.products.map((p) => {
  14. return Math.round(10.0 * p.price / p.boxingVolume) / 10.0;
  15. }));
  16. const secondBeerLittreMinPrice = Math.min.apply(Math, second.products.map((p) => {
  17. return Math.round(10.0 * p.price / p.boxingVolume) / 10.0;
  18. }));
  19. if (firstBeerLittreMinPrice > secondBeerLittreMinPrice) return 1;
  20. if (firstBeerLittreMinPrice < secondBeerLittreMinPrice) return -1;
  21. if (firstBeerLittreMinPrice == secondBeerLittreMinPrice) return 0;
  22. } else if (queryParams.sorting === 'новинки') {
  23. if (first.timestamp < second.timestamp) return 1;
  24. if (first.timestamp > second.timestamp) return -1;
  25. if (first.timestamp == second.timestamp) return 0;
  26. }
  27. });
Add Comment
Please, Sign In to add comment