Below is an illustration of the data available:
$scope.allmovies[
{title:"Harry Potter", time:130},
{title:"Star Wars", time:155},
{title:"Lord of the Rings", time:250},
{title:"Goonies", time:125},
{title:"Fast and Furious", time:140}
];
var mostpopular=[
$scope.allmovies[0],
$scope.allmovies[2]
];
var recentlyadded=[
$scope.allmovies[1],
$scope.allmovies[3],
$scope.allmovies[4]
];
$scope.playlists={
mostpoplularmoves:{
title:"Most Popular Movies",
price:"$5.99",
Number:mostpopular.length,
TotalTime: LOOP THROUGH VAR MOSTPOPULAR AND CALCULATE THE TOTAL TIME OF ALL MOVIES
},
recentlyaddedmovies:{
title:"Recently Added Movies",
price:"$2.99",
Number:recentlyadded.length,
TotalTime:LOOP THROUGH VAR RECENTLYADDED AND DETERMINE THE TOTAL TIME OF ALL MOVIES
}
};
I need help in looping through the arrays above to sum up all the times and obtain a total time for each playlist (mostpopular[0].time+=totalTime then mostpopular[1].time+=totalTime etc.... or something similar). Is this achievable and if so, what would be the correct syntax? Thank you for your assistance