Skip to content

Instantly share code, notes, and snippets.

@fogonthedowns
Created July 31, 2014 00:56
Show Gist options
  • Save fogonthedowns/d07b3894b8cf33193aee to your computer and use it in GitHub Desktop.
Save fogonthedowns/d07b3894b8cf33193aee to your computer and use it in GitHub Desktop.
longestfirst.rb
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