diff --git a/00_hello/hello.rb b/00_hello/hello.rb index 251797306..d51f4a31c 100644 --- a/00_hello/hello.rb +++ b/00_hello/hello.rb @@ -1 +1,7 @@ -#write your code here +def hello() + return "Hello!" +end + +def greet(name) + return "Hello, #{name}!" +end diff --git a/01_temperature/temperature.rb b/01_temperature/temperature.rb index 251797306..1bee36fa6 100644 --- a/01_temperature/temperature.rb +++ b/01_temperature/temperature.rb @@ -1 +1,7 @@ -#write your code here +def ftoc(a) + return ((a - 32)/1.8).round(2) +end + +def ctof(b) + return ((b * 1.8) + 32) +end diff --git a/02_calculator/calculator.rb b/02_calculator/calculator.rb index 251797306..49bd6067c 100644 --- a/02_calculator/calculator.rb +++ b/02_calculator/calculator.rb @@ -1 +1,15 @@ -#write your code here +def add(a,b) + return a + b +end + +def subtract(a,b) + return a - b +end + +def sum(a) + c = 0 + a.each do |b| + c += b + end + return c +end diff --git a/02_calculator/calculator_spec.rb b/02_calculator/calculator_spec.rb index fef7e9d00..f7017a930 100644 --- a/02_calculator/calculator_spec.rb +++ b/02_calculator/calculator_spec.rb @@ -82,7 +82,7 @@ it "multiplies two numbers" it "multiplies several numbers" - + end describe "#power" do diff --git a/03_simon_says/simon_says.rb b/03_simon_says/simon_says.rb index 251797306..0ecc6a40e 100644 --- a/03_simon_says/simon_says.rb +++ b/03_simon_says/simon_says.rb @@ -1 +1,42 @@ #write your code here +def echo(a) + return a +end + +def shout(a) + return(a).upcase! +end + +def repeat(a, b = 0) + if b == 0 + return "#{a} #{a}" + else + c = [] + b.times do + c << a + end + return c.join(" ") + end +end + +def start_of_word(a, b) + return a[0..(b - 1)] +end + +def first_word(a) + return a.split(" ")[0] +end + +def titleize(a) + skip = ["and", "or", "the", "over"] + c = [] + a.split(" ").each do |b| + if skip.include? b + c << b + else + c << b.capitalize! + end + end + c[0] = a.split(" ")[0].capitalize! + return c.join(" ") +end diff --git a/04_pig_latin/pig_latin.rb b/04_pig_latin/pig_latin.rb index 251797306..a847abcd3 100644 --- a/04_pig_latin/pig_latin.rb +++ b/04_pig_latin/pig_latin.rb @@ -1 +1,30 @@ -#write your code here +def translate(a) + + vow = ["a", "e", "i", "o", "u", "y"] + ay = "ay" + phrase = [] + + a.split(" ").each do |w| + # -- cas "squ" -- + if w.index("squ") + w = w.split(//).rotate(3) + word = w.join("") + ay + # -- cas "qu" -- + elsif w.index("qu") + w = w.split(//).rotate(2) + word = w.join("") + ay + # -- voyelle -- + elsif vow.include? w[0] + word = w + ay + # -- consonne rotate jusqu'à voyelle -- + else + w = w.split(//) + w.rotate! until vow.include? w[0] + word = w.join("") + ay + end + + phrase << word + end + + return phrase.join(" ") +end diff --git a/05_book_titles/book.rb b/05_book_titles/book.rb index 009f2643e..f8d52711f 100644 --- a/05_book_titles/book.rb +++ b/05_book_titles/book.rb @@ -1,3 +1,33 @@ class Book -# write your code here + attr_accessor :title + + def title=(new) + c = [] + conjunctions = ["and", "but", "for", "nor", "or", "so", "yet"] + prepositions = ["over", "in", "of"] + articles = ["the", "a", "an"] + # new = new.to_s + new.split(" ").each do |b| + if conjunctions.include? b + c << b + elsif prepositions.include? b + c << b + elsif articles.include? b + c << b + elsif b.length == 1 && b == "i" + c << b.upcase! + elsif b.is_a? Integer + # print b + c << b + else + c << b.capitalize! + end + @title = c.join(" ") + end + end + end + + +puts @book = Book.new +puts @book.title = "I Knew When I was 20"