diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..2b2567e9 Binary files /dev/null and b/.DS_Store differ diff --git a/lib/00_hello.rb b/lib/00_hello.rb index a5fd1d52..17341fa5 100644 --- a/lib/00_hello.rb +++ b/lib/00_hello.rb @@ -1,7 +1,10 @@ def hello - + return "Hello!" end def greet(name) - + return "Hello, #{name}!" end + + + diff --git a/lib/01_temperature.rb b/lib/01_temperature.rb new file mode 100644 index 00000000..328a7985 --- /dev/null +++ b/lib/01_temperature.rb @@ -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 + diff --git a/lib/02_calculator.rb b/lib/02_calculator.rb new file mode 100644 index 00000000..539a593d --- /dev/null +++ b/lib/02_calculator.rb @@ -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 + + \ No newline at end of file diff --git a/lib/03_basics.rb b/lib/03_basics.rb new file mode 100644 index 00000000..15a7bdea --- /dev/null +++ b/lib/03_basics.rb @@ -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 + diff --git a/lib/04_simon_says.rb b/lib/04_simon_says.rb new file mode 100644 index 00000000..d4e38fe6 --- /dev/null +++ b/lib/04_simon_says.rb @@ -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") \ No newline at end of file diff --git a/lib/05_timer.rb b/lib/05_timer.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/06_pig_latin.rb b/lib/06_pig_latin.rb new file mode 100644 index 00000000..e69de29b diff --git a/spec/02_calculator_spec.rb b/spec/02_calculator_spec.rb index 08ed2d7f..8c3309c0 100644 --- a/spec/02_calculator_spec.rb +++ b/spec/02_calculator_spec.rb @@ -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