Level 3 · Programming Skills · Course 3.1 JavaScript Programming
Module 22: Loops and Algorithms
Goal: plan the steps a program takes before writing it, and use loops and array methods to transform, search, sort and total data, with a feel for which approaches stay fast as data grows.
You'll need: your level-3 folder and catalogue.js from Module 21.
Lessons
- 1What an algorithm is15–25 minutes✓
- 2Transforming data with map, filter and reduce15–25 minutes✓
- 3Searching15–25 minutes✓
- 4Sorting15–25 minutes✓
- 5Efficiency15–25 minutes✓
🛠️Module practice: Project A, part 2, a catalogue report
Extend catalogue.js to print a report:
- Total number of products and total stock value (with
reduce). - Products that need reordering (stock below 5), sorted by stock.
- The number of products in each category (hint:
reduceinto an object, or a loop). - A
searchProducts(query)function that ignores case and spaces. - The three most expensive products, without changing the original array.
Write the pseudocode for each part first, as comments. Commit.
✅Module check
Explain in a few sentences, in your own words:
What's an algorithm, and why might code that works perfectly with 100 items become unusable with 100,000?
Show a good answer
A good answer mentions: an algorithm is a precise set of steps from input to output, planned in pseudocode
before coding; map, filter, reduce, search and sort are common building blocks. Code with a loop inside a loop
(for example find inside map over large lists) grows with the square of the data: fine for 100 items, but
billions of steps for 100,000. Building a Map or Set for lookups keeps it fast.
📝Module quiz
10 questions · 10 marks each · 100 marks in all · pass mark 70% · retry as often as you like ·
