Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1ere repo #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Binary file added .DS_Store
Binary file not shown.
7 changes: 5 additions & 2 deletions lib/00_hello.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
def hello

return "Hello!"
end

def greet(name)

return "Hello, #{name}!"
end



8 changes: 8 additions & 0 deletions lib/01_temperature.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def ftoc(temperature)
return ((temperature-32)/1.8).round(1)
end

def ctof(temperature)
return (temperature*1.8+32).round(1)
end

32 changes: 32 additions & 0 deletions lib/02_calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def add(a,b)
return a + b
end

def subtract(a,b)
return a - b
end

def sum(a)
return a.inject(0, :+)
end

def multiply(a,b)
a = a.to_i
b = b.to_i
return a*b
end

def power(a,b)
return a**b
end

def factorial(a)
b = 1
while a > 0
b = b * a
a = a-1
end
return b
end


23 changes: 23 additions & 0 deletions lib/03_basics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def who_is_bigger(a,b,c)

if a == nil || b == nil || c == nil #gestion d'un nil, en a, b ou c
return "nil detected"
else
hash = {a:a, b:b, c:c} #création d'un hash pur associer une clé a,b,c pour chaque valeur de a, b et c
return "#{hash.key(hash.values.max)} is bigger" #la key de la valeur max
end
end

def reverse_upcase_noLTA(word)
word.upcase.reverse.delete"ALT"
end

def array_42(*array)
array = array.to_s #conversion en string pour permettre la bonne execution de la fonction .include
return array.include? "42"
end

def magic_array (*array)
return array.flatten.sort.map{|x| x*2}.delete_if{|x| x%3 == 0}.uniq
end

24 changes: 24 additions & 0 deletions lib/04_simon_says.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def echo(word)
return word
end

def shout(word)
return word.upcase
end

def repeat(word, b=2)
return ((word + " ") * b).strip
end

def start_of_word (word, b = 1)
return word [0, b]
end

def first_word(word)
return word.split(' ').first
end

def titleize(word)
return
end
puts titleize("hello you")
Empty file added lib/05_timer.rb
Empty file.
Empty file added lib/06_pig_latin.rb
Empty file.
34 changes: 25 additions & 9 deletions spec/02_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,39 @@
expect(multiply(3, 4)).to eq(12)
end

it "multiplies two other numbers"
it "multiplies two other numbers" do
expect(multiply(2, 2)).to eq(4)
end
# one other test here, don't forget do end ;)

it "multiplies two other numbers, one of them being 0"
it "multiplies two other numbers, one of them being 0" do
expect(multiply(2, 0)).to eq(0)
# one last test, with 0 in it

end
end

describe "#power" do
it "raises one number to the power of another number"
it "raises one number to the power of another number" do
expect(power(2,2)).to eq(4)
end
end


# http://en.wikipedia.org/wiki/Factorial
describe "#factorial" do
it "computes the factorial of 0"
it "computes the factorial of 1"
it "computes the factorial of 2"
it "computes the factorial of 5"
it "computes the factorial of 10"
it "computes the factorial of 0"do
expect(factorial(0)).to eq(1)
end
it "computes the factorial of 1" do
expect(factorial(1)).to eq(1)
end
it "computes the factorial of 2"do
expect(factorial(2)).to eq(2)
end
it "computes the factorial of 5" do
expect(factorial(5)).to eq(120)
end
it "computes the factorial of 10" do
expect(factorial(10)).to eq(3628800)
end
end