Looking for a benefactor
Description:
The accounts of the "Fat to Fit Club (FFC)" association are supervised by John as a volunteered accountant.
The association is funded through financial donations from generous benefactors. John has a list of
the first n
donations: [14, 30, 5, 7, 9, 11, 15]
He wants to know how much the next benefactor should give to the association so that the
average of the first n + 1
donations should reach an average of 30
.
After doing the math he found 149
. He thinks that he could have made a mistake.
Could you help him?
Task
The function should return the expected donation (rounded up to the next integer) that will permit to reach the average.
Should the last donation be a non positive number (<= 0)
John wants us either to throw an error or return such value so he will clearly see that his expectations are not great enough.
In "Sample Tests" you can see what to return.
Notes:
- all donations and new average are numbers (integers or floats), array of donations can be empty.
- See examples below and "Sample Tests" to see which return is to be done.
array: [14, 30, 5, 7, 9, 11, 15], new average: 92 -> result: 645
array: [14, 30, 5, 7, 9, 11, 15], new average: 2 -> result: variable, see "Sample Tests"
Similar Kata:
Stats:
Created | Jan 17, 2016 |
Published | Jan 17, 2016 |
Warriors Trained | 25394 |
Total Skips | 3010 |
Total Code Submissions | 93050 |
Total Times Completed | 10441 |
Ruby Completions | 325 |
Python Completions | 2574 |
JavaScript Completions | 2356 |
CoffeeScript Completions | 19 |
Java Completions | 1190 |
C# Completions | 468 |
Clojure Completions | 105 |
Haskell Completions | 183 |
Elixir Completions | 197 |
TypeScript Completions | 238 |
C++ Completions | 674 |
PHP Completions | 348 |
Crystal Completions | 15 |
F# Completions | 74 |
C Completions | 396 |
OCaml Completions | 59 |
Rust Completions | 437 |
R Completions | 132 |
Nim Completions | 30 |
Shell Completions | 88 |
Kotlin Completions | 375 |
Fortran Completions | 37 |
Julia Completions | 40 |
PowerShell Completions | 78 |
Go Completions | 425 |
Reason Completions | 12 |
Racket Completions | 30 |
Scala Completions | 109 |
Prolog Completions | 29 |
Lua Completions | 81 |
Pascal Completions | 14 |
Perl Completions | 41 |
Elm Completions | 10 |
D Completions | 12 |
Erlang Completions | 13 |
Total Stars | 215 |
% of votes with a positive feedback rating | 79% of 1438 |
Total "Very Satisfied" Votes | 973 |
Total "Somewhat Satisfied" Votes | 334 |
Total "Not Satisfied" Votes | 131 |