Functions and data
Breaking programs into functions, and choosing the right shape for your data: arrays, objects, Maps and Sets. Array methods and modern syntax make this code short and clear.
About 14 hours of study
Learning objectives
- Design functions that take values and return results
- Explain the difference between a value and a reference
- Answer questions about data with map, filter and reduce
- Choose between an array, object, Map and Set
Lessons
- 1
Functions and the call stack
Writing functions with parameters and return values, default parameters, arrow functions, the call stack that keeps track of calls, and recursion.
- 2
Arrays
Lists of values: indexes, length, adding and removing with push, pop, shift and unshift, slice and splice, and why two variables can share one array.
- 3
Objects
Grouping values with names: object literals, reading and changing properties with dot and bracket notation, methods and this, looping over keys, destructuring, and JSON.
- 4
Array methods: forEach, map, filter and reduce
Passing a function to another function: callbacks, forEach, map, filter, find, some, every, reduce and sort, and chaining them to answer questions about data.
- 5
Destructuring, spread and safe access
The modern shorthand you will meet in almost every JavaScript file: unpacking arrays and objects, the spread and rest dots, optional chaining and the nullish operator.
- 6
Maps and Sets
Two collections built for looking things up: Map for pairs of keys and values, and Set for groups without repeats, and how to choose between them and plain objects.
Module practice
- Reverse the wordsEasy
- Greatest common divisorMedium
- The Towers of HanoiHard
- The largest number and where it isEasy
- Rotate a listMedium
- Merge two sorted listsHard
- A student recordEasy
- Count the wordsMedium
- A shop's stockHard
- Squares of the even numbersEasy
- Total of an orderMedium
- Group students by gradeHard
- First, last and the middleEasy
- Settings with defaultsMedium
- Reading a path through dataHard
- Remove the repeatsEasy
- The first repeated wordMedium
- Group the anagramsHard