Rullst AcademyRullst Academy/Lesson
JavaScript and interaction · Lesson 05 / 14

Lists with identity

Two missions can share a title without being the same mission.

Learning paths16 min

Let's discover together

  1. 1

    An object groups properties, such as {id:1, title:"Read", minutes:15, done:false}. An array keeps a sequence of objects. Its first index is zero; length gives the count, not the last index.

  2. 2

    for...of iterates values. map creates a new array with a transformation; filter keeps items whose predicate is true. Neither freezes contained objects: an array copy is not a deep copy.

  3. 3

    A stable id distinguishes missions with identical titles. Do not use the filtered position as identity: removal and filtering change indices. The project generates increasing local ids without personal data.

  4. 4

    Use find to look up a mission by id; absence returns undefined. Sum with an accumulator or reduce starting at zero. An empty list must produce zero without error.

From the example to your own interaction

Download this activity kit, extract it and open index.html in a browser. Edit lesson.js, save and reload. You do not need Node or packages. README explains local HTTP when needed.

The demonstration uses supplied JavaScript. It does not execute your editor code. Download your edit separately to test in the local kit.

My files and GitHub
Try the project we will build

Small mission planner

Create, complete and review a study plan using fictional data. Missions stay only in this page’s memory and disappear on reload.

Use a short title without personal data and whole minutes from 1 to 120. Up to 20 missions.

Missions in the plan
0
Minutes across all missions
0
Completed missions
0

No missions in this filter. Add one or choose another filter.

    Suggestion lab

    Scenarios are simulated in this browser by default. No suggestion request is sent and your plan is not replaced.

    Available in the kit opened at http://127.0.0.1:8768. See README; no external account is needed.

      This JSON contains only missions, not your code. The demonstration does not import files or synchronize devices. Download edited JavaScript from the lesson file workspace.

      Official links and next step

      ✦
      YOUR MISSION

      Represent missions with objects and iterate, filter and transform arrays.

      Now it's your turn

      Discovery workshop

      Think before running

      The list contains {id:1, minutes:15, done:false} and {id:2, minutes:20, done:true}.
      Build your answers and check when you are ready.
      A moment to understand

      Which identity survives a filter?

      I need a hint

      Predict the result, run your file and explain the difference.

      Loading your journey…

      Take it with you

      Create duplicate titles with different ids. Filter, change one mission by id and record which stayed intact.

      At your own pace

      My files and GitHub

      Every lesson can become your own record: code, notes or a practice plan. Saving a file to GitHub is optional and does not change your XP.

      Student guide

      The editor and downloads open when this lesson is available to your account. Check access below or return to the track map.

      Checking your access to this lesson…

      Rullstpetbot

      AI can make mistakes. Check the lesson material.