Created
July 31, 2014 00:56
-
-
Save fogonthedowns/d07b3894b8cf33193aee to your computer and use it in GitHub Desktop.
longestfirst.rb
This file contains hidden or 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
file_path = ARGV[0] | |
number_of_lines = ARGV[1] || 10 | |
answer = {} | |
number_of_lines = number_of_lines.to_i | |
if file_path.nil? | |
puts "you must include a file path" | |
else | |
File.open(file_path).each_with_index do |line, index| | |
answer[index] = line | |
end | |
answer.each{|k,v| v.chomp!} | |
answer = answer.sort_by{|key,value| value.size} | |
answer.reverse! | |
(0..number_of_lines).each {|x| puts answer[x][1] unless answer[x].nil?} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment