Skip to content

Instantly share code, notes, and snippets.

@tejaswini-dev-techie
Created August 2, 2024 10:50
Show Gist options
  • Select an option

  • Save tejaswini-dev-techie/7911c3b399feb1c08862ee5a7ddb8e6c to your computer and use it in GitHub Desktop.

Select an option

Save tejaswini-dev-techie/7911c3b399feb1c08862ee5a7ddb8e6c to your computer and use it in GitHub Desktop.
Total Video Count Calculator: Summing up all videos across modules
void main() {
List<Map<String, dynamic>> sampleData = [
{
"module_id": "7",
"module_title": "Introduction",
"videos": [
{"sn_no": 1, "sno": "01", "video_id": "1668"},
{"sn_no": 2, "sno": "02", "video_id": "4"},
{"sn_no": 3, "sno": "03", "video_id": "38"},
{"sn_no": 4, "sno": "04", "video_id": "39"}
]
},
{
"module_id": "24",
"module_title": "Learning",
"videos": [
{"sn_no": 5, "sno": "05", "video_id": "37"},
{"sn_no": 6, "sno": "06", "video_id": "36"},
{"sn_no": 7, "sno": "07", "video_id": "35"},
]
},
{
"module_id": "25",
"videos": [
{"sn_no": 8, "sno": "08", "video_id": "34"},
{"sn_no": 9, "sno": "09", "video_id": "2"},
{"sn_no": 10, "sno": "10", "video_id": "6"}
]
}
];
int totalVideosCount = 0; // Variable to store the total count of videos
for (var module in sampleData) {
if (module.containsKey("videos")) {
totalVideosCount += (module["videos"] as List).length;
}
}
print("Total videos count is: $totalVideosCount");
}
@tejaswini-dev-techie
Copy link
Author

This Dart script calculates and prints the total number of videos from a list of modules, summing up the count of videos present in each module.

Outcome

total_video_count

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment