Last active
August 29, 2015 13:56
-
-
Save dgreenbe77/9149957 to your computer and use it in GitHub Desktop.
List_Stasts
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
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Be careful about leaving trailing whitespace in your files. You've got a blank space on the lines that are separating your methods:
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