Last active
February 5, 2016 02:44
-
-
Save JoshCheek/765e5b89c271fe170bdd to your computer and use it in GitHub Desktop.
Solutions to Command Line Arguments homework (https://github.com/CodePlatoon/curriculum/blob/master/phase1/command-line-arguments-homework.md)
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
left = ARGV.shift.to_f | |
while 0 < ARGV.length | |
operator = ARGV.shift | |
right = ARGV.shift.to_f | |
if '+' == operator | |
left += right | |
elsif '-' == operator | |
left -= right | |
elsif '*' == operator | |
left *= right | |
elsif '/' == operator | |
left /= right | |
end | |
end | |
puts left |
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
$stdout.puts ARGV.join |
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
index = ARGV.shift.to_i | |
$stdout.puts ARGV[index] |
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
longest = "" | |
comparer = ARGV.shift | |
ARGV.each do |arg| | |
if comparer == 'first' | |
longest = arg if longest.length < arg.length | |
else | |
longest = arg if longest.length <= arg.length | |
end | |
end | |
$stdout.puts longest unless longest.length == 0 |
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
ARGV.each { |arg| $stdout.puts arg } |
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
longest = "" | |
ARGV.each { |arg| longest = arg if longest.length < arg.length } | |
$stdout.puts longest unless longest.length == 0 |
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
longest = "" | |
ARGV.each { |arg| longest = arg if longest.length <= arg.length } | |
$stdout.puts longest unless longest.length == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment