Skip to content

Commit

Permalink
Finished structural changes (#81)
Browse files Browse the repository at this point in the history
* restructured readme

* added readme to assignments

* restructered

* cleaned up

* added zeros to single digit numbers

* cleaned up

* restructured 01-learning style

* Create readme.md

* cleaned up

* added numbers to headings

* fixed links

* cleaned up

* cleaned up

* added folder for jump start live

* Update and rename README.md to readme.md

* Update readme.md

* Update readme.md

* Update readme.md

* Create pretty-code.md

* Create conditionals.md

* Create loops.md

* Update loops.md

* Create more-loops.md

* Create arrays.md

* Create hashes.md

* Create readme.md

* Update readme.md

* Update readme.md

* Update readme.md

* removed jump-start-live; has its own place

* restructured and cleaned up

* restructured and cleaned up

* fixed titles

* fixed assignment links

* fixed article linking structure

* fixed link structure

* clean up

* fixed link structure

* removed term bold styles

* major updates to reduce to a single page

* formatting fixes

* formatting fixes

* major changes to reduce to a single page

* small formatting change

* major updates to reduce to a single page

* some small content fixes

* fixed optional readings section

* major updates; unfinished

* removed unnecessary files

* reordered

* removed unneccessary files

* reordered content

* fixed names

* cleaned up; renamed

* renamed

* fixed table headings

* switched to activies, from assignments

* added note about not having a mac

* formatting fix

* formatting fix

* fixed names

* content fixes

* fixed imgs

* content fixes

* reorg

* Fixed links

* Fixed links

* adjusted grouping

* fixed intros

* massive re-structring and content fixes

* fixed links

* uggggh

* content fixes

* major updates to content and structure

* formatting fix

* formatting fix

* formatting fix

* formatting fix

* formatting fix

* removed img of truth table

* content fixes

* content fixes

* major restructuring of content

* updated learning goals

* moved from lessons to section folders

* updates

* added blank doc for applyign to ada

* added link for applying to ada

* fixed overviews and links

* fixed heading

* fixed img link

* fixed order of content

* fixed img link

* fixed headings

* fixed img links

* fixed links
  • Loading branch information
susanev committed Jan 21, 2018
1 parent ed96d64 commit a8e732b
Show file tree
Hide file tree
Showing 68 changed files with 506 additions and 862 deletions.
141 changes: 13 additions & 128 deletions lessons/arrays/README.md → learning-to-code/arrays/README.md
@@ -1,4 +1,4 @@
# Basic Data Structures: Arrays and Hashes
# Arrays
_Jump start: Lesson 12_

## Learning Goals
Expand All @@ -10,16 +10,13 @@ _Jump start: Lesson 12_
- To understand the difference between an array and a hash
- To know the syntax needed to create a new array and hash

## Resources
1. [Notes: Arrays](notes/arrays.md)
1. [Assignment: Array Worksheet](assignments/array-worksheet.md)
1. [Assignment: Account Generator](assignments/account-generator.md)
1. [Notes: Hashes](notes/hashes.md)
1. [Assignment: Hash Worksheet](assignments/hash-worksheet.md)
1. [Assignment: Account Generator Continued](assignments/account-generator-cont.md)
1. [Assignment: Walk-a-thon](assignments/walkathon.md)
## Activities
* Review the notes in this section
* Complete [Array Worksheet](assignments/array-worksheet.md)
* Complete [Account Generator](assignments/account-generator.md)

# Notes: Arrays
## Notes
### Overview
Arrays are the most common data type used to create collections in Ruby.

An `Array` is an _ordered_ collection of objects.
Expand All @@ -32,7 +29,7 @@ Array Example:
### Creating Arrays
There are two different ways to create a new Array.

#### Empty
### Empty
In the first way, we initialize an empty `Array` by using `[]`. An array can be assigned to a variable like any other data type:

```ruby
Expand All @@ -47,27 +44,27 @@ The second way is to explicitly create a new instance of the `Array` object defi
my_array = Array.new
```

#### With Data
### With Data
We can utilize the syntax for both of the above to initialize a new Array _with data_.

```ruby
numbers = [1, 2, 3, 4]
```
![numbers array](../images/array-1.png)
![numbers array](./images/array-1.png)

We can do something similar when creating an array using `Array.new`. When passing parameters into `new`, the first parameter will be the size of the desired array. The second parameter will be the default value for all element within the array.

```ruby
empty_array = Array.new(3)
empty_array # => [nil, nil, nil]
```
![empty_array](../images/array-2.png)
![empty_array](./images/array-2.png)

```ruby
default_array = Array.new(3, "def")
default_array # => ["def", "def", "def"]
```
![default_array](../images/array-3.png)
![default_array](./images/array-3.png)

### Indices
Arrays are integer-indexed starting at __zero__. All counting in computer science [begins with zero](http://skillcrush.com/2013/01/17/why-programmers-start-counting-at-zero/). This means that **each item** in the array corresponds to an **integer value**, and that integer is used to access an object within the `Array`. The first object is assigned 0 and increments up from there.
Expand All @@ -81,7 +78,7 @@ numbers[3] # => 50
numbers[4] # => 2
numbers[5] # => 7
```
![my_array](../images/array-4.png)
![my_array](./images/array-4.png)

### Data Types
Arrays can store all sorts of data. Usually, it makes the most sense to have a single data type in an array, but in Ruby, it is not a requirement.
Expand Down Expand Up @@ -167,115 +164,3 @@ cats = ["grumpy"]
cats.first # => "grumpy"
cats.last # => "grumpy"
```

# Notes: Hashes

A `Hash` is another very popular collection type in Ruby. It is similar to an Array, except that indexing is done via unordered _keys_ of any object type, and _not an ordered integer index_.

```ruby
{ "key1" => "key1sAssociatedValue", "key2" => "key2sAssociatedValue" ...}
```

### Creating Hashes
We initialize an empty `Hash` by using `{}` (pronounced _brace_). A hash can be assigned to a variable in the same or a similar way that other types of data are assigned to a variable:

#### Empty

```ruby
my_hash = {}
```

```ruby
my_hash = Hash.new
```

We know that this hash is empty because the hash definition starts with the `{`(left brace) and ends with the `}`(right brace), and there is nothing between those two symbols.

#### With Data

By using the `new` syntax and specifying a default value, _all_ keys retrieved with no corresponding value will return the default value. Without the default value, accessing an undefined key will return `nil`.

```ruby
my_hash = Hash.new
my_hash["gibberish"] # => nil

default_data = Hash.new("def")

# By creating a hash with a default value,
# all data retrievals will return the default value if not specified otherwise
default_data["gibberish"] # => "def"
```

You can also create a new hash with key/value pairs populated.

```ruby
my_dog = {
"name" => "barkly",
"breed" => "beagle",
"age" => 2
}
```

### Accessing Data
To access data from within a hash, we use a syntax that is similar to accessing data in an Array. The difference is that we use the strings that correspond to the key to retrieve the associated value.

```ruby
my_dog["age"] # => 2
my_dog["breed"] # => "spaniel"
my_dog["name"] # => "barkly"

# by default, will return nil for keys that don't exist
my_dog["color"] # => nil
```

### Assigning Data
We can utilize our understanding of reassigning values in Arrays to assign and reassign values in a Hash.

Assuming that we want to add a **new** key value pair to an **existing** hash, we can choose the key that we want to set the value for. In the case below, we have decided that we want to set the value `"blenheim"` for a new key `"color"`.

```ruby
# Add a new key value pair for color
my_dog["color"] = "blenheim"
```

In addition, we can reset the value associated with an existing key using the same syntax. In the case below, we would like to set the `"age"` value to `3` from it's original `2`.
```ruby
# Retrieve the value currently set
my_dog["age"] # => 2

# Reassign the value associated with the age key
my_dog["age"] = 3

# Retrieve the updated value
my_dog["age"] # => 3
```

### Using Built-In Methods

#### length
This method returns the number of items in the hash. An item corresponds to a key/value pair.

```ruby
my_dog = {
"name" => "barkly",
"breed" => "beagle",
"age" => 2
}

my_dog.length # => 3
```

#### keys
This method returns an _array_ of all the defined keys for the hash.

```ruby
my_dog.keys #=> ["name", "breed", "age"]
```

#### values
This method returns an _array_ of all the values of all defined keys for the hash.

```ruby
my_dog.values #=> ["barkly", "beagle", 3]
```

File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
129 changes: 129 additions & 0 deletions learning-to-code/hashes/README.md
@@ -0,0 +1,129 @@
# Hashes
_Jump start: Lesson 13_

## Learning Goals
- Vocabulary: data structure, array, index, value, hash, key-value pair, default value
- To understand what a data structure is and how it can be used
- To be able to create a new array and hash data structure
- To be able to access data in an array and hash
- To be able to add data to an array and hash
- To understand the difference between an array and a hash
- To know the syntax needed to create a new array and hash

## Activities
* Review the notes in this section
* Complete [Hash Worksheet](assignments/hash-worksheet.md)
* Complete [Account Generator Continued](assignments/account-generator-cont.md)
* Complete [Walk-a-thon](assignments/walkathon.md)

## Notes
### Overview
A `Hash` is another very popular collection type in Ruby. It is similar to an Array, except that indexing is done via unordered _keys_ of any object type, and _not an ordered integer index_.

```ruby
{ "key1" => "key1sAssociatedValue", "key2" => "key2sAssociatedValue" ...}
```

### Creating Hashes
We initialize an empty `Hash` by using `{}` (pronounced _brace_). A hash can be assigned to a variable in the same or a similar way that other types of data are assigned to a variable:

### Empty

```ruby
my_hash = {}
```

```ruby
my_hash = Hash.new
```

We know that this hash is empty because the hash definition starts with the `{`(left brace) and ends with the `}`(right brace), and there is nothing between those two symbols.

### With Data

By using the `new` syntax and specifying a default value, _all_ keys retrieved with no corresponding value will return the default value. Without the default value, accessing an undefined key will return `nil`.

```ruby
my_hash = Hash.new
my_hash["gibberish"] # => nil

default_data = Hash.new("def")

# By creating a hash with a default value,
# all data retrievals will return the default value if not specified otherwise
default_data["gibberish"] # => "def"
```

You can also create a new hash with key/value pairs populated.

```ruby
my_dog = {
"name" => "barkly",
"breed" => "beagle",
"age" => 2
}
```

### Accessing Data
To access data from within a hash, we use a syntax that is similar to accessing data in an Array. The difference is that we use the strings that correspond to the key to retrieve the associated value.

```ruby
my_dog["age"] # => 2
my_dog["breed"] # => "spaniel"
my_dog["name"] # => "barkly"

# by default, will return nil for keys that don't exist
my_dog["color"] # => nil
```

### Assigning Data
We can utilize our understanding of reassigning values in Arrays to assign and reassign values in a Hash.

Assuming that we want to add a **new** key value pair to an **existing** hash, we can choose the key that we want to set the value for. In the case below, we have decided that we want to set the value `"blenheim"` for a new key `"color"`.

```ruby
# Add a new key value pair for color
my_dog["color"] = "blenheim"
```

In addition, we can reset the value associated with an existing key using the same syntax. In the case below, we would like to set the `"age"` value to `3` from it's original `2`.
```ruby
# Retrieve the value currently set
my_dog["age"] # => 2

# Reassign the value associated with the age key
my_dog["age"] = 3

# Retrieve the updated value
my_dog["age"] # => 3
```

### Using Built-In Methods

#### length
This method returns the number of items in the hash. An item corresponds to a key/value pair.

```ruby
my_dog = {
"name" => "barkly",
"breed" => "beagle",
"age" => 2
}

my_dog.length # => 3
```

#### keys
This method returns an _array_ of all the defined keys for the hash.

```ruby
my_dog.keys #=> ["name", "breed", "age"]
```

#### values
This method returns an _array_ of all the values of all defined keys for the hash.

```ruby
my_dog.values #=> ["barkly", "beagle", 3]
```

File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Expand Up @@ -11,13 +11,13 @@ A _Hello World_ program is the first program that people often write when explor
## Activities
* Read about the history of [Hello, World!](https://en.wikipedia.org/wiki/%22Hello,_World!%22_program)
* Write and execute a hello world program in the terminal using `irb`
1. Open terminal
1. Type `irb` and press [enter]
1. Type `puts "Hello, World!"` and press [enter]
1. Open terminal
2. Type `irb` and press [enter]
3. Type `puts "Hello, World!"` and press [enter]
* Write a hello world program in a Ruby file and execute it form the terminal
1. Open terminal
1. Type `touch hello-world.rb` to create the file
1. Type `atom .` to open the file in Atom
1. Type `puts "Hello, World"` and save the file
1. In terminal type `ruby hello-world.rb` and press [enter]
1. Open terminal
2. Type `touch hello-world.rb` to create the file
3. Type `atom .` to open the file in Atom
4. Type `puts "Hello, World"` and save the file
5. In terminal type `ruby hello-world.rb` and press [enter]
* Reflect on the steps you completed, and try them a few more times without referencing the instructions to practice

0 comments on commit a8e732b

Please sign in to comment.