Skip to content

Instantly share code, notes, and snippets.

@dgreenbe77
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dgreenbe77/9149957 to your computer and use it in GitHub Desktop.
Save dgreenbe77/9149957 to your computer and use it in GitHub Desktop.
List_Stasts
require 'pry'
def sort_from_biggest_to_smallest(sorted_statistics, unsorted_statistics)
unsorted = unsorted_statistics
popped_number = unsorted_statistics.pop
sorted = sorted_statistics
remaining_unsorted_objects = []
if unsorted.empty?
return sorted
end
until unsorted.empty?
if popped_number <= unsorted.last
remaining_unsorted_objects << popped_number
popped_number = unsorted.pop
else
remaining_unsorted_objects << unsorted.pop
end
end
sorted << popped_number
sort_from_biggest_to_smallest(sorted, remaining_unsorted_objects)
end
def average_number(unsorted_statistics)
total = 0
unsorted_statistics.each do |number|
total += number
end
average_number = total / unsorted_statistics.length
end
max_number = sort_from_biggest_to_smallest([],[75, 100, 85, 65, 84, 87, 95]).shift
min_number = sort_from_biggest_to_smallest([],[75, 100, 85, 65, 84, 87, 95]).pop
average = average_number([75, 100, 85, 65, 84, 87, 95])
puts average
puts min_number
puts max_number
@HeroicEric
Copy link

Try to be careful to set the correct language when posting a gist. This will make it easier to read for everybody by providing syntax highlighting hello

@dpickett
Copy link

Good work!

  • the indentation looks very proper and in line with ruby conventions!
  • when creating gists, if you save the file as a .rb, we will get the benefit of Github's ruby syntax highlighting.
  • The program's output should give us more context around the numbers you are outputting? Which one is the average? Which one is the min?
  • nice use of a sorting algorithm! Can you identify the min and the max without sorting the list?
  • Should the average be an instance of Float?

@HeroicEric
Copy link

Be careful about leaving trailing whitespace in your files. You've got a blank space on the lines that are separating your methods:

Trailing Space

Make sure you've got all of the Sublime Text settings provided in the install guide. Here they are again https://gist.github.com/HeroicEric/77c860d2fe8d7ae0a98f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment