Skip to content

Conversation

@inlibra-cpa
Copy link

Created multiple programs for Lesson 2.1:
full_name.rb
leap_year.rb
sorted_words.rb
add_up.rb

Copy link

@ZipDevil ZipDevil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean code and good use of build-in methods.

@@ -0,0 +1,6 @@
def add_up(a)
sum = 0
sum = (1..a).inject{ |s, i| s + i }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of inject here!

if starting_year % 4 == 0
puts starting_year
elsif starting_year % 100 == 0
elsif starting_year % 400 == 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the conditional (if/else) statement, we like to start with edge cases and then other possibilities.
So here the if/else block would be:

if starting_year % 400 == 0
    puts "#{starting_year} is leap year."
elsif starting_year % 4 = 0 && starting_yea % 100 != 0 
    puts "#{starting_year} is leap year."
end

@inlibra-cpa
Copy link
Author

inlibra-cpa commented Nov 16, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants