Calculate the Total Budget

You're working as an accountant for a company that manages the finances of various clients. Each client has a specific budget allocated to them. To better manage the finances, you need to calculate the total budget of all the clients combined.

Instructions:

  • Write a function named getBudgets that takes an array of objects as input. Each object represents a client and contains their name, age, and budget.

  • The function should return the sum of all the budgets.

Note: Only use the map, filter, or reduce methods, or a combination of these methods, to solve the problem. Do not use loops to iterate or perform the operation.

Example 1

Input: getBudgets([ { name: "Alice", age: 25, budget: 30000 }, { name: "Bob", age: 30, budget: 15000 }, { name: "Charlie", age: 35, budget: 50000 } ]);
Output: 95000

Example 2

Input: getBudgets([ { name: "David", age: 29, budget: 1000 }, { name: "Edward", age: 40, budget: 2000 } ]);
Output: 3000

Example 3

Input: getBudgets([]);
Output: 0

Are you stuck on this problem?

Get detailed, step-by-step solution and improve your JavaScript skills.

  • Detailed Explanation: Each solution comes with a comprehensive explanation, helping you understand the logic and concepts thoroughly.
  • Learn to Write Better Code: Even if you have written the code, discover ways to improve it and adopt best practices.
  • Save Time: Don’t waste hours struggling—get the solution and learn efficiently.
  • Lifetime Access: Get access to lifetime solutions for all problems available
Get the Solution

" I struggled with this problem for hours, but the solution provided here was clear and easy to follow. It helped me understand where I went wrong and improved my coding skills significantly." - Jane D.

If you're not satisfied, I offer a 7-day money-back guarantee.