As someone new to JavaScript, I apologize if my description of the issue is not clear. It's challenging for me to explain the problem I am facing.
I have a computed function where I use the reduce method to iterate over my objects, perform calculations within the loop to find new variables, and then return an array with the summed values.
I am able to return the sum of a single variable inside the loop, but I'm struggling to return two variables from the computed function. My solution is to convert these two values into an array and somehow return their sum, so that I can use these values in future calculations. Could you please provide some guidance on how to tackle this issue?
new Vue({
el: "#demo",
data() {
return {
objects: {
price: 0,
amount: 0,
percent: 0,
fee: 0,
solution_cost: {dry:0, wet: 0}
},
},
computed: {
solutionCost() {
//Looping through my objects
const total = this.objects.reduce((sum, object) => {
let solution_cost_dry = object.amount / object.price;
let solution_cost_wet = object.solution_cost[dry] * object.percent;
// Unsure how to sum "dry" and "wet" values and store them in an array
return object.solution_cost: sum + {dry:solution_cost_dry, wet:solution_cost_wet }
}, 0)
// Returning an array with the summed values {dry:solution_cost_dry, wet:solution_cost_wet }
return total[];
},
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>