ALAB 308H.10.1 - Iterators and Generators


Learning Objectives

By the end of this lab, learners will have demonstrated the ability to:

  • Create iterable iterators using generator functions.

 CodeSandbox

This lab uses CodeSandbox as one of its tools.

If you are unfamiliar with CodeSandbox, or need a refresher, please visit our reference page on CodeSandbox for instructions on:

  • Creating an Account
  • Making a Sandbox
  • Navigating your Sandbox
  • Submitting a link to your Sandbox to Canvas

Instructions

  1. Fork this CodeSandbox and name it "Iterators and Generators Lab."
  2. Follow along with the instructions below.
  3. Submit the link to your CodeSandbox on Canvas when you are finished.

Deliverables

  1. A link to a CodeSandbox that contains your completed lab with no errors (comment things out if they do not work).

Getting Started

The index.js file in the provided CodeSandbox includes some skeleton code to get you started.

For this lab, create two generator functions:

  • fibonacci, which yields the fibonacci sequence, infinitely.
  • primes, which yields prime numbers, infinitely.

Test your generators using the LazyList that was created during Lesson 308H.10 - Iterators and Generators, which has been included for you within the provided CodeSandbox. Some sample tests have been provided for you, along with their expected outputs. Feel free to test your code in additional ways!

Copyright © Per Scholas 2024