Skip to content
This repository has been archived by the owner on May 17, 2022. It is now read-only.

Latest commit

 

History

History

conditional-statements

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Conditional Statements

Introduction

We can't do much without logic. The following tasks are a couple of computing problems that you may have seen before.

Objective

Start to get familiar with some of the conditional expressions in Ruby.

Tasks

Task 1

Write three functions that compute the sum of the numbers in a given list using a for-loop, a while-loop, and recursion.

Task 2

Write a function that combines two lists by alternatingly taking elements.

For example:

# Given the two lists...

list_one = [a, b, c]
lsit_two = [1, 2, 3]

# The end result should be...

[a, 1, b, 2, c, 3]

Task 3

Write a function that computes the list of the first 100 Fibonacci numbers.

By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two.

As an example, here are the first 10 Fibonnaci numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, and 34.

Notes

Note: If you want to define a method or two during this exercise, you can do this by:

def your_method_name(arg_one, arg_two)
  # some
  # code
  # here

  return_value # this is returned from your method
end

Extension

What does the and keyword do? Is there anything special about it?