This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define a method that take a sentence and return the acronyme | |
# ex: | |
# puts acronymize("Gnu not unix") | |
# >"GNU" | |
def acronymize(sentence) | |
acronyme = "" | |
#Change string to array | |
sentence.split.each do |word| | |
acronyme += word[0].upcase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
def highlow(array) | |
min = array[0] | |
max = array[0] | |
for number in array | |
if number < min | |
min = number | |
end | |
if number > max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Choose a hand for the computer | |
# Ask the user his hand | |
# Compare both hands | |
# Define result | |
# store result | |
# print result | |
# let's do it again | |
CHOICE = ["Pierre","Feuille","Ciseaux"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_variable = "hello" #snakecase | |
puts my_variable | |
my_variable += " world" | |
puts my_variable | |
def water_color(color = "blue") | |
return color | |
end | |
puts water_color("green") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#condition | |
puts "Quelle température fait-il?" | |
print ">" | |
temp = gets.chomp.to_i | |
# def is_cool?(temp, ceil) | |
# return temp <= ceil | |
# end | |
# puts is_cool?(temp, 24) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# boucles: while, loop, until, for | |
for i in (1...100) | |
puts "Voici le nombre #{i}" | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# La poste est ouverte de 10h à 12h et de 14h à 16h | |
# si time > 10 et < 12 | |
# si time >14 et <16 | |
def la_poste_is_open?(time) | |
time >= 10 && time <= 12 || time >= 14 && time <= 16 | |
end | |
puts la_poste_is_open?(9) | |
puts la_poste_is_open?(11) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
profs = %w(cécile gab boris seb edward kevin) | |
profs.sort! | |
profs.each_with_index do |prof, index| | |
puts "#{index + 1}. #{prof.capitalize!}" | |
end | |
p profs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
array = ['Michel Polnareff', 'Michel Jonasz', 'Michel Delpech', 'Maxime Leforestier'] | |
# "Mr" | |
new_array = [] | |
array.each do |singer| | |
new_array << "Mr #{singer}" | |
end | |
# p new_array | |
# MAP | |
# input : array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# COUNT | |
# input : array | |
# output: fixnum = number of element which match with condition | |
array = ['Michel Polnareff', 'Michel Jonasz', 'Michel Delpech', 'Maxime Leforestier'] | |
counter = 0 | |
array.each do |singer| | |
if singer.split[1].downcase.include?("o") | |
counter += 1 | |
end |
OlderNewer