Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion 00_hello/hello.rb
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
#write your code here
def hello()
return "Hello!"
end

def greet(name)
return "Hello, #{name}!"
end
8 changes: 7 additions & 1 deletion 01_temperature/temperature.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 15 additions & 1 deletion 02_calculator/calculator.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion 02_calculator/calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
it "multiplies two numbers"

it "multiplies several numbers"

end

describe "#power" do
Expand Down
41 changes: 41 additions & 0 deletions 03_simon_says/simon_says.rb
Original file line number Diff line number Diff line change
@@ -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
31 changes: 30 additions & 1 deletion 04_pig_latin/pig_latin.rb
Original file line number Diff line number Diff line change
@@ -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
32 changes: 31 additions & 1 deletion 05_book_titles/book.rb
Original file line number Diff line number Diff line change
@@ -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"