Skip to content

Commit

Permalink
Added Arrays chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
anowak2692 committed Sep 25, 2014
1 parent cd0b6fd commit 1263801
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
3 changes: 3 additions & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
* [Else](conditional/else.md)
* [Comparators](conditional/comparators.md)
* [Concatenate](conditional/concatenate.md)
* [Arrays](arrays/README.md)
* [Indicies](indicies.md)
* [Length](length.md)
* [Loops](loops/README.md)
* [For](loops/for.md)
* [While](loops/while.md)
Expand Down
11 changes: 11 additions & 0 deletions arrays/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Arrays

Arrays are a fundamental part of programming. An array is a list of data. We can store a lot of data in one variable, which makes our code more readable and easier to understand. It also makes it much easier to perform functions on related data.

The data in arrays are called **elements**.

Here is a simple array:
```javascript
// 1, 1, 2, 3, 5, and 8 are the elements in this array
var numbers = [1, 1, 2, 3, 5, 8];
```
41 changes: 41 additions & 0 deletions arrays/indicies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Indicies

So you have your array of data elements, but what if you want to access a specific element? That is where indicies come in. An **index** refers to a spot in the array. Indicies logically progress one by one, but it should be noted that the first index in an array is 0, as it is in most languages. Brackets [] are used to signify you are referring to an index of an array.

```javascript
// This is an array of strings
var fruits = ["apple", "banana", "pineapple", "strawberry"];

// We set the variable banana to the value of the second element of
// the fruits array. Remember that indicies start at 0, so 1 is the
// second element. Result: banana = "banana"
var banana = fruits[1];
```
---

Define the variables using the indices of the array

```js
var cars = ["Mazda", "Honda", "Chevy", "Ford"]
var honda =
var ford =
var chevy =
var mazda =
```

```js
var cars = ["Mazda", "Honda", "Chevy", "Ford"]
var honda = cars[1];
var ford = cars[3];
var chevy = cars[2];
var mazda = cars[0];
```

```js
assert(honda === "Honda");
assert(ford === "Ford");
assert(chevy === "Chevy");
assert(mazda === "Mazda");
```

---
31 changes: 31 additions & 0 deletions arrays/length.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Length

Arrays have a property called length, and it's pretty much exactly as it sounds, it's the length of the array.

```javascript
var array = [1 , 2, 3];

// Result: l = 3
var l = array.length;
```

---

Define the variable a to be the number value of the length of the array

```js
var array = [1, 1, 2, 3, 5, 8];
var l = array.length;
var a =
```

```js
var array = [1, 1, 2, 3, 5, 8];
var l = array.length;
var a = 6;
```

```js
assert (a === 6)
```
---

0 comments on commit 1263801

Please sign in to comment.