Loop like an ES6 Native
One of the first things someone learns in programming is to loop, i.e. perform a sequence of steps on a set of elements. Any developer - beginner to advanced, writes atleast a few loops every hour. It’s ubiqutious nature merits a deep dive into the fundamentals of looping.
ES6 comes bundled with many of these including the new generator syntax, which we will dig deep into, so your loops going forward can be both machine-efficient, and developer-friendly.
- Various ways to loop
- for … of loop and it’s comparison
- for … of loop working on Maps, Sets, Args, DOM collections
- Examples from other languages
- “Array Like” and “Duck Typing”
- Benefits with example - Unit Testing
- Within the builtins
- Iterators returned
- Iterables consumed
- spread operator
- min, max etc.
- Consistent interface
- Under the hood - The Protocols
- Iterator Protocol
- Iterable Protocol
- Custom Iterators/iterables
- Builtin function
- Lazy evaluation
- Implements both iterator and iterable protocol
- Keywords - yield, yield, function
- Generators example
- Example of a normal program
- Example of AJAX chaining
- Generators Algorithm example
- Recursive algorithm for fibonacci
- Generator algo
- Recursion algorithm for factors of a number
- Generator algorithm
- Your own generators in the real world
Lakshman Prasad has been programming for a decade and finds ways to do efficiently, things that are often done. He works for a management consulting firm in developing technology solutions.