• in
InterCourses
CoursesBlogs
0
← Introduction to JavaScript
○What is JavaScript?○Your First JavaScript Code○Data Types○Type Checking
○Declaring Variables○let and const in Practice○Operators○Type Conversion
○Conditionals○Switch Statement○For Loops○While Loop○Break and Continue
○Defining Functions○Arrow Functions○Scope○Closures○Project - Calculator○Function Expressions
○Arrays○Array Mutation Methods○Array Search and Slice○Array Iteration Methods○Multidimensional Arrays○Destructuring○Array Reverse and Sort○Array Fill○Array Find and Includes○Array Flat and FlatMap○Array Reduce, Some, and Every
○Objects○Object Methods and Destructuring○JSON○Math and Date○Date Basics
○02 Template Literals○String Methods○Regular Expressions
○Higher-Order Functions○Callbacks●map, filter, and reduce○Recursion○Project - Data Transform Pipeline
○OOP Introduction○Classes○Inheritance○Encapsulation
○Asynchronous JavaScript○Promises and Async Await○Async API Simulation

map, filter, and reduce

These three methods are the workhorses of functional JavaScript. Chain them together for expressive data pipelines.

Combining all three

javascript
const orders = [
    { product: "Book", price: 12, qty: 2 },
    { product: "Pen",  price: 1,  qty: 10 },
    { product: "Bag",  price: 35, qty: 1 }
];

const total = orders
    .filter(o => o.qty > 1)                   // keep multiple-quantity orders
    .map(o => o.price * o.qty)                // calculate line total
    .reduce((sum, lineTotal) => sum + lineTotal, 0); // sum up

console.log(total); // 34 (12*2 + 1*10 = 24 + 10)

Your Task

Given:

javascript
const employees = [
    { name: "Alice",  dept: "Engineering", salary: 95000 },
    { name: "Bob",    dept: "Marketing",   salary: 72000 },
    { name: "Carol",  dept: "Engineering", salary: 108000 },
    { name: "Dave",   dept: "Marketing",   salary: 68000 },
    { name: "Eve",    dept: "Engineering", salary: 120000 }
];
  1. engineeringNames — an array of names of employees in "Engineering" (use filter + map).
  2. avgEngineerSalary — the average salary of Engineering employees (use filter + reduce), rounded to the nearest integer.
  3. salaryReport — an array of strings like "Alice: $95,000" for all employees (use map + toLocaleString).
  4. Display in #output: "Engineers: Alice,Carol,Eve | Avg salary: $107,667".
Hint 1
1 / 3
HINT 1

map transforms — returns a new array of the same length.

Loading editor…
READY
intercourses
javascript