Skip to content
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

two answer options for get_file_extention question #189

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions challenges/getFileExtension/solutions/get_file_extension.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Option 1
# def get_file_extention(file_name: raise)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for your contribution! 🎉 Just a nitpick: extension is mistyped as extention here and below.

# extensions_ary = file_name.split(".")
# extensions_ary.size == 1 ? (return false) : (return extensions_ary.last)
# end

# Option 2 - Library function
def get_file_extention(file_name: raise)
ext = File.extname(file_name).gsub(".","")
ext.empty? ? false : ext
end

# Test cases
file_names = ["data.txt", "index.html.erb", ".aws.txt", "foo"]

file_names.each {|name|
puts "file name for #{name} is #{get_file_extention(file_name: name)}"
}