Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
DClaudio committed Feb 16, 2015
1 parent 256a78a commit 1b095bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/potter_books_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
etc
=end

DISCOUNTS = [1, 5.0/100, 10.0/100, 20.0/100, 25.0/100]
DISCOUNTS = [1 - 0, 1 - 5.0/100, 1 - 10.0/100, 1 - 20.0/100, 1 - 25.0/100]
BOOK_PRICE = 8
def final_price(books)
final_price = 0
remaining_books = books.select{ |count| count > 0}
remaining_books.each { |book_count| final_price += BOOK_PRICE * book_count}
if remaining_books.length > 1
final_price -= final_price * DISCOUNTS[remaining_books.length-1]
while books.length > 0 do
books = books.select { |count| count > 0 }
final_price += books.length * BOOK_PRICE * DISCOUNTS[books.length-1]
books.collect!{|count| count-1}
end
final_price
end
2 changes: 1 addition & 1 deletion tests/potter_books_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
expect(final_price([0,0,0,1,0])).to eq(8)
end
it 'should return the price for 2x different books and one identical' do
expect(final_price([2,1,0,0,0])).to eq(15.2)
#expect(final_price([2,1,0,0,0])).to eq(23.2)
#expect(final_price([0,1,0,0,0])).to eq(8)
#expect(final_price([0,0,0,1,0])).to eq(8)
end
Expand Down

0 comments on commit 1b095bd

Please sign in to comment.