From 800596340bdc347788de7a6d50c65c2cbf9ef08f Mon Sep 17 00:00:00 2001 From: Chloe Date: Sat, 21 Sep 2019 15:30:47 -0700 Subject: [PATCH] some of them done --- .DS_Store | Bin 0 -> 8196 bytes 00_hello/hello.rb | 8 +++++++- 01_temperature/temperature.rb | 7 +++++++ 02_calculator/calculator.rb | 29 ++++++++++++++++++++++++++ 02_calculator/calculator_spec.rb | 4 ++-- 03_simon_says/simon_says.rb | 34 +++++++++++++++++++++++++++++++ Gemfile.lock | 6 +++--- 7 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2c67e277337ddd2c295468fa86974433e6f410a4 GIT binary patch literal 8196 zcmeHM&u-H&9R7JLTUs{O1JZWP1&PBnwcFSZ6H+Oi&<;q5A~*ork~VD7(zt3;s!@u1 z;T?cC;8A!29)t&g?`NAS$vOlV#DpE$pJRWY|9o-cxg#Rc9CqtOYeeKAGFGo6nGv|2 zwtCOUvL0>HV5aDeP7qw)H+}t_%9vc z?}LlT*f2QNs6HJ?)DZw!La_?S^KpPRuEB=EsYcWw2rUI_sW3+jq2(xd4Xf)Y;;nCEv2(*=N~Hc{Xi8BjNmM zLC3St>KuBEF`c5Pnf>sLg_D_a8T@^^M=g2?+`#y{`5t)AImHTIs6@SB9XQod&y@Q* zhI&ALUd`(vr!M`}7I>I{j)!T@4!j&)M8<}}sYWj1a=ZVt5jI!{uAl?+ddzEl{@=g+ z_x~$6GdpDKfOX(^9T25fyVV3+?dmgByvw_YM~EDlH`S;lNOFG&;Qss{hRD01vZi5h Tsu3j!_J;svgH5ahf7O8>ckLX~ literal 0 HcmV?d00001 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