7 kyu

Looking for a benefactor

325 of 10,441g964

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" 
Fundamentals
Arrays

More By Author:

Check out these other kata created by g964

Stats:

CreatedJan 17, 2016
PublishedJan 17, 2016
Warriors Trained25394
Total Skips3010
Total Code Submissions93050
Total Times Completed10441
Ruby Completions325
Python Completions2574
JavaScript Completions2356
CoffeeScript Completions19
Java Completions1190
C# Completions468
Clojure Completions105
Haskell Completions183
Elixir Completions197
TypeScript Completions238
C++ Completions674
PHP Completions348
Crystal Completions15
F# Completions74
C Completions396
OCaml Completions59
Rust Completions437
R Completions132
Nim Completions30
Shell Completions88
Kotlin Completions375
Fortran Completions37
Julia Completions40
PowerShell Completions78
Go Completions425
Reason Completions12
Racket Completions30
Scala Completions109
Prolog Completions29
Lua Completions81
Pascal Completions14
Perl Completions41
Elm Completions10
D Completions12
Erlang Completions13
Total Stars215
% of votes with a positive feedback rating79% of 1438
Total "Very Satisfied" Votes973
Total "Somewhat Satisfied" Votes334
Total "Not Satisfied" Votes131
Ad
Contributors
  • g964 Avatar
  • GiacomoSorbi Avatar
  • kazk Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • Madjosz Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • 4500zenja1 Avatar
  • KayleighWasTaken Avatar
Ad