diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 000000000..2c67e2773 Binary files /dev/null and b/.DS_Store differ diff --git a/00_hello/hello.rb b/00_hello/hello.rb index 251797306..234606ee4 100644 --- a/00_hello/hello.rb +++ b/00_hello/hello.rb @@ -1 +1,7 @@ -#write your code here +def hello + "Hello!" +end + +def greet(name) + "Hello, #{name}!" +end diff --git a/01_temperature/temperature.rb b/01_temperature/temperature.rb index 251797306..b6a8c05bd 100644 --- a/01_temperature/temperature.rb +++ b/01_temperature/temperature.rb @@ -1 +1,8 @@ #write your code here +def ftoc(f) + (f-32.0) * (5.0/9.0) +end + +def ctof(c) + c * (9.0/5.0) + 32 +end \ No newline at end of file diff --git a/02_calculator/calculator.rb b/02_calculator/calculator.rb index 251797306..6e90abafd 100644 --- a/02_calculator/calculator.rb +++ b/02_calculator/calculator.rb @@ -1 +1,30 @@ #write your code here +def add(x, y) + x + y +end + +def subtract(x,y) + x - y +end + +def sum(array) + array.inject(0){|total,number| total + number} +end + + +def multiply(x,y) + x * y +end + +def power(x,y) + x ** y +end + + +def factorial(x) + if x <= 1 + 1 + else + x * factorial(x-1) + end +end \ No newline at end of file diff --git a/02_calculator/calculator_spec.rb b/02_calculator/calculator_spec.rb index fef7e9d00..3c436b3a4 100644 --- a/02_calculator/calculator_spec.rb +++ b/02_calculator/calculator_spec.rb @@ -77,11 +77,11 @@ # once the above tests pass, # write tests and code for the following: -describe "#multiply" do +describe "multiply" do it "multiplies two numbers" + expect(multiply(2,3)).to eq(6) - it "multiplies several numbers" end diff --git a/03_simon_says/simon_says.rb b/03_simon_says/simon_says.rb index 251797306..7be4052da 100644 --- a/03_simon_says/simon_says.rb +++ b/03_simon_says/simon_says.rb @@ -1 +1,35 @@ #write your code here +def echo(x) + x +end + +def shout(x) + x.upcase +end + +def repeat(x, times = 2) + ([x] * times).join(" ") +end + +def start_of_word(x , n) + x[0 ... n] +end + +def first_word(x) + x.split(" ").first +end + +def titleize(s) + words = s.split.map do |word| + if ["and", "the","over"].include? word + word + else + word.capitalize + end + ends + words[0].capitalize! + words.join(" ") + words +end + + diff --git a/Gemfile.lock b/Gemfile.lock index ab1e7db63..5e8aebfc8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ GEM remote: https://rubygems.org/ specs: diff-lcs (1.3) - rake (10.5.0) + rake (12.3.3) rspec (3.5.0) rspec-core (~> 3.5.0) rspec-expectations (~> 3.5.0) @@ -21,8 +21,8 @@ PLATFORMS ruby DEPENDENCIES - rake (< 11.0) + rake (~> 12.3) rspec (~> 3.4) BUNDLED WITH - 1.13.6 + 1.17.2