-
Couldn't load subscription status.
- Fork 74
Submit Lesson 2.1 assignment #9
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
base: master
Are you sure you want to change the base?
Submit Lesson 2.1 assignment #9
Conversation
There was a problem hiding this 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 } | |||
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
|
Thank you Jasper!
Appreciate it!
…On Tue, Nov 16, 2021, 10:57 Jasper Lin ***@***.***> wrote:
***@***.**** commented on this pull request.
Very clean code and good use of build-in methods.
------------------------------
In add_up.rb
<#9 (comment)>
:
> @@ -0,0 +1,6 @@
+def add_up(a)
+ sum = 0
+ sum = (1..a).inject{ |s, i| s + i }
Good use of inject here!
------------------------------
In leap_year.rb
<#9 (comment)>
:
> @@ -0,0 +1,14 @@
+puts "Enter starting_year"
+starting_year = gets.to_i
+puts "Enter ending_year"
+ending_year = gets.to_i
+puts ""
+while starting_year.to_i <= ending_year.to_i
+if starting_year % 4 == 0
+ puts starting_year
+elsif starting_year % 100 == 0
+elsif starting_year % 400 == 0
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
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#9 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANDMFNVD5BSU7GVNTBPQI7LUMJ5PRANCNFSM5HH3NHEQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Created multiple programs for Lesson 2.1:
full_name.rb
leap_year.rb
sorted_words.rb
add_up.rb