Created
July 6, 2016 22:21
-
-
Save Andy-Bell/b6cea7b53676080aa6c56cdd3811c075 to your computer and use it in GitHub Desktop.
current implementation of deluxe fizzbuzz
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 App | |
def initialize | |
@output = [] | |
end | |
def fizz_buzz(number) | |
@number = number | |
builder | |
result = { true => @output.join(" "), false => number } | |
result[(output.length > 0)] | |
end | |
private | |
attr_reader :output, :number, :truth, :array | |
FIZZ = 3 | |
BUZZ = 5 | |
def builder | |
@output.push("fizz") if fizzable | |
@output.push("buzz") if buzzable | |
@output.push("deluxe") if deluxeable | |
@output.insert(-2,"fake") if deluxeable && number.odd? | |
end | |
def fizzable | |
(number % FIZZ) == 0 || number_check(FIZZ) | |
end | |
def buzzable | |
(number % BUZZ) == 0 || number_check(BUZZ) | |
end | |
def deluxeable | |
(number_check(FIZZ) && number % FIZZ == 0) || (number_check(BUZZ) && number % BUZZ == 0 ) | |
end | |
def number_check(test) | |
@array = "#{number}".split(//) | |
@truth = [] | |
iterate_array(test) | |
check = { true => true, false => false} | |
check[truth.include?(true)] | |
end | |
def iterate_array(test) | |
array.each do |x| | |
@truth.push(true) if x.to_i == test | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment