map, filter, reduce
These three operations are the backbone of data transformation. Most data pipelines boil down to some combination of them.
- map — transform each element
- filter — keep only elements matching a condition
- reduce — collapse all elements into one value
Given a list of integers, apply this pipeline in order:
- Filter out any numbers less than 0
- Map each remaining number to its square
- Reduce the squares to their sum
Print the final sum. If the list is empty after filtering, print 0.
Input: 3,-1,4,-1,5,9
Output: 131 // 3²+4²+5²+9² = 9+16+25+81 = 131
Constraints
- Implement each step separately — don't combine them into one loop.
- Numbers are comma-separated integers.
Ad SpaceGoogle AdSense active for guests & free-tier learners.