PencilCoder

Bracket Notation!

Goals:

  • Use bracket notation to access and overwrite elements of an array

Coding Snippets:

  • coding snippets
  • An array is an ordered list of values. Each value, or element, has a corresponding index that refers to its position in the list.
  • Bracket notation allows us to reference specific elements of an array using indexes, instead of resorting to array destructuring.
  • Arrays are 0-indexed, meaning the first element has index 0. Thus, dimensions[0] references the page width.

Math and Computer Concepts:

  • Bracket notation is the conceptual equivalent of the subscripts used in math to denote elements in a list. For example, x[0] and x[1] correspond to x0 and x1. Moreover, these expressions are pronounced the same way, i.e., "x sub zero" and "x sub one".
  • Coding ExampleBracket notation makes it possible to iterate over two or more arrays simultaneously. For example, given corresponding arrays grade and weight, we can compute a weighted average as follows:

Activities:

Save each of the following in a folder called BracketNotation.