Code Recipes / Exercise

Try three practical JavaScript recipes

Search original deduplication, grouping and average recipes, then edit and run each one.

You will learn to

  • Preserve order while deduplicating
  • Group records by key
  • Define an empty-average result

Before you start

JavaScript arrays

A recipe is a contract

Copying a snippet without its assumptions creates debugging work. Each original recipe has a supported example and a check. Search returns only the recipes that actually run.

Know the boundaries

Set deduplicates primitive values but does not merge objects with equal fields. Grouping should use a Map or a null-prototype dictionary when keys are untrusted. Returning null for an empty average communicates that no measurement exists instead of inventing a zero.

Make one change

Establish a baseline, then change the input and predict the output before running again. These checks are a starting point, not a production test suite. Add cases for your domain.

Try it yourself

Enable JavaScript for this interactive activity. You can read all lesson explanations above without it.

Continue exploring