Skip to content

Submit Lesson 2.1 assignment#9

Open
inlibra-cpa wants to merge 1 commit into
Code-the-Dream-School:masterfrom
inlibra-cpa:ruby-collections-lesson
Open

Submit Lesson 2.1 assignment#9
inlibra-cpa wants to merge 1 commit into
Code-the-Dream-School:masterfrom
inlibra-cpa:ruby-collections-lesson

Conversation

@inlibra-cpa
Copy link
Copy Markdown

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

Copy link
Copy Markdown

@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.

Comment thread add_up.rb
@@ -0,0 +1,6 @@
def add_up(a)
sum = 0
sum = (1..a).inject{ |s, i| s + i }
Copy link
Copy Markdown

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!

Comment thread leap_year.rb
if starting_year % 4 == 0
puts starting_year
elsif starting_year % 100 == 0
elsif starting_year % 400 == 0
Copy link
Copy Markdown

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
Copy Markdown
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