This file contains 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 Array | |
# found this online | |
def mode | |
self.group_by{|i| i}.max{|x,y| x[1].length <=> y[1].length}[0] | |
end | |
# another version | |
def mode2 | |
group_by {|x| x}.group_by {|k,v| v.size}.sort.last.last.map(&:first) |
This file contains 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 FizzBuzz | |
def initialize(x) | |
@a=*(1..x) | |
end | |
def run | |
@a.each do |x| | |
y = ((x.to_f)/3.0).to_s.split(".") | |
z = ((x.to_f)/5.0).to_s.split(".") |
This file contains 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 'rubygems' | |
require 'lingua/stemmer' | |
class WordReview | |
def initialize | |
@h = Hash.new | |
end | |
def load_file(file) |
This file contains 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 Array | |
def median(arr) | |
arr.sort! | |
x = arr.count | |
if( x%2 == 0) | |
#even number | |
x /= 2 | |
(arr[x] + arr[x-1])/2.0 | |
elsif( x%2 > 0) |
This file contains 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 SquareSums | |
def initialize(arr) | |
@arr = arr | |
@col = 0 | |
@row = 0 | |
end | |
def add_square | |
tally = [] |