Topic Overview

Welcome! The focus of today's lesson is on data aggregation, a practical concept utilizing Maps as our primary tool. In TypeScript, we leverage its rich type system to ensure safer and more robust code.

Data aggregation refers to gathering "raw" data and subsequently presenting it in an analysis-friendly format. An illustrative analogy is viewing a cityscape from an airplane, providing an informative aerial overview rather than delving into the specifics of individual buildings. We will guide you through operations such as Sum, Average, Count, Maximum, and Minimum for practical, hands-on experience, using TypeScript's types for enhanced reliability and clarity.

Let's continue!

Summing Values in a Map

We will begin with a hands-on example using a fruit basket represented as a Map. First, create a new Map with type annotations and set the quantities of various fruits:

Next, sum the values in the Map. Start with a variable to hold the total number of fruits, explicitly typing it:

Finally, print the total:

Counting Elements in a Map
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal