I am currently working on a task that involves calculating the total number of hours from an array. Within this array, there are various sessions each with their own time frame for completion. The challenge I face is that the hour values are stored as strings.
Here is an example of how the data is structured:
[
{ "id": 1,
"exercise": "1.1",
"name": "Session one",
"hours": "1"
},
{ "id": 2,
"exercise": "1.2",
"name": "Session two",
"hours": "4"
},
{ "id": 3,
"exercise": "1.3",
"name": "Session three",
"hours": "0,5"
}
]
The desired total should be 5.5 hours in this case.
I have attempted to filter out the array like so:
computed: {
hours() {
var hours = 0;
this.data.filter((item => {
hours += item.hours;
}));
return hours;
}
},
However, the result returned is unexpectedly high.