Skip to content

Instantly share code, notes, and snippets.

View mikedao's full-sized avatar
🤷

Michael Dao mikedao

🤷
View GitHub Profile
You have an array of integers, and for each index you want to find the product of every integer except the integer at that index.
Write a function get_products_of_all_ints_except_at_index() that takes an array of integers and returns an array of the products.
For example, given:
[1, 7, 3, 4]
your function would return:

Input Format

You are given an integer N depicting the height of the staircase.

Output Format

Print a staircase of height N that consists of # symbols and spaces as given in Sample Output.

Sample Input

age = 5
puts "#{('happy ' * age).capitalize}birthday!"
string = "Denver"
puts "#{string[0]}#{string.length - 2}#{string[-1]}"

Codebreakers

We're going to be writing a program to do some basic text encryption through everyone's friend, the command line.

Iteration 1 - Initials

We're first going to start with an exercise to figure out how we can get code entered on the command line.

Create a file called initials.rb.

diff --git a/lib/district.rb b/lib/district.rb
new file mode 100644
index 0000000..ebe98f8
--- /dev/null
+++ b/lib/district.rb
@@ -0,0 +1,10 @@
+class District
+ attr_reader :name
+
+ attr_accessor :enrollment
id first_name last_name phone_number age
1 taylor swift 5555555 25
2 jeff wan 2222222 35
3 luna lovegood 3333333 17

Anchor

  • Project Schedule
  • Session Assignment / Google Calendar
  • 1 on 1s
  • Full Group Classes
  • Portfolio Rubric
  • Scope and Sequence
  • Portfolio Promotion Decision
  • Assessment Content / Design
  • Revising Lessons

Exercises

  • If you had an array of numbers, e.g. [1,2,3,4], how do you print out the doubles of each number? Triples?
  • If you had the same array, how would you only print out the even numbers? What about the odd numbers?
  • How could you create a new array which contains each number multipled by 2?
  • Given an array of first and last names, e.g. ["Alice Smith", "Bob Evans", "Roy Rogers"], how would you print out the full names line by line?
  • How would you print out only the first name?