Task List Utilities

Write task list helpers that return updated arrays.

Start building, submit solution and get feedback from the community.
2Submit Solution
5 upvotes10 upvotes

Task List Utilities

You are writing helper functions for a task list. Each helper should return a result without mutating the original tasks array.

Write these functions:

  • addTask(tasks, title) should return a new array with a new incomplete task added.

  • completeTask(tasks, taskId) should return a new array where only the matching task is completed.

  • removeTask(tasks, taskId) should return a new array without the matching task.

  • countIncompleteTasks(tasks) should return the number of incomplete tasks.

Sample checks:

js
const tasks = [  { id: 1, title: 'Review variables', completed: true },  { id: 2, title: 'Practice functions', completed: false },];const withNewTask = addTask(tasks, 'Build task utilities');console.log(withNewTask.map((task) => task.title));const completed = completeTask(withNewTask, 2);console.log(countIncompleteTasks(completed));console.log(removeTask(completed, 1).map((task) => task.id));console.log(tasks.length);console.log(countIncompleteTasks(tasks));

Expected output:

txt
["Review variables", "Practice functions", "Build task utilities"]1[2, 3]21

The original tasks array should still have two items after these helper functions run.

Join the Community

roadmap.sh is the most starred project on GitHub and is visited by hundreds of thousands of developers every month.

Rank  out of 28M!

361K

GitHub Stars

Star us on GitHub
Help us reach #1

+90k every month

+2.1M

Registered Users

Register yourself
Commit to your growth

+2k every month

49K

Discord Members

Join on Discord
Join the community

Roadmaps Best Practices Guides Videos FAQs YouTube

roadmap.sh by @kamrify

Community created roadmaps, best practices, projects, articles, resources and journeys to help you choose your path and grow in your career.

ThewNewStack

The top DevOps resource for Kubernetes, cloud-native computing, and large-scale development and deployment.