It's possible that I'm doing something wrong, but I do not understand the following result. I get the product Array (sorted by name) from the server. Now I need the lowest and highest price for a price slider so that I'm using computed properties. After that, the complete product array is sorted by price and I can't understand why?
data:
products: []
...
methods: {
loadProducts() {
...
this.products = response.data.elements; //array is sorted correct by name
}
},
computed:
maxPriceCalc: function() {
var products = this.products;
if(productss.length > 0) {
var maxPrice = productss.sort(compare); //at this point - this.products is sorted by price too
return maxPrice[0].calculatedPrice.totalPrice;
}
function compare(a, b) {
if (a.calculatedPrice.totalPrice > b.calculatedPrice.totalPrice)
return -1;
if (a.calculatedPrice.totalPrice < b.calculatedPrice.totalPrice)
return 1;
return 0;
}
...
Maybe anyone has an idea to figure it out.
Thx for time and help.