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
    
  
  
    
  | class RPNCalculator | |
| def evaluate(expression) | |
| array = expression.split(' ') | |
| until array.length == 1 | |
| array.each_with_index do |item, index| | |
| if item == "+" || item == "*" || item == "-" | |
| array[index] = eval(array[index - 2] + array[index] + array[index - 1]).to_s | 
  
    
      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
    
  
  
    
  | def factorial(n) | |
| total = 1 | |
| 1.upto(n) {|x| total = total * x} | |
| return total | |
| end | 
  
    
      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
    
  
  
    
  | def count_between(array, lower_bound, upper_bound) | |
| array.find_all {|x| x >= lower_bound && x <= upper_bound}.count | |
| end | 
  
    
      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
    
  
  
    
  | class GuessingGame | |
| attr_accessor :answer, :high, :low, :correct, :guess, :last_guess, :last_result | |
| def initialize(answer) | |
| @answer = answer | |
| @last_result = nil | |
| @last_guess = nil | |
| end | |
  
    
      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
    
  
  
    
  | def longest_string(array) | |
| var = array.sort_by { |x| x.length } | |
| var.last | |
| end | 
  
    
      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
    
  
  
    
  | def mode(array) | |
| counts = {} | |
| mode = [] | |
| array.each do |number| | |
| counts[number] = counts[number].to_i + 1 | |
| end | |
| largest_count = counts.invert.sort.to_a.last.first | |
| counts.each_pair do |number, count| | |
| mode << number if count == largest_count | |
| end | 
  
    
      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
    
  
  
    
  | def median(array) | |
| med = array.length / 2 | |
| index1 = array[med - 1] | |
| index2 = array[med] | |
| odd = (array.length + 1) / 2 | |
| if array.length % 2 == 0 | |
| return (index1.to_f + index2.to_f) / 2 | |
| else | |
| return array[odd - 1] | 
  
    
      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
    
  
  
    
  | def mean(array) | |
| total = array.inject{|sum, x| sum + x} | |
| total / array.length.to_f | |
| end | 
  
    
      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
    
  
  
    
  | def get_grade(array) | |
| average = (array.inject(:+) / array.size) | |
| if average >= 90; "A" | |
| elsif average >= 80; "B" | |
| elsif average >= 70; "C" | |
| elsif average >= 60; "D" | |
| else average >= 50; "F" | |
| end | |
| end |