6 kyu
Recursive Averages
312joh_pot
Description:
This kata is based on the Ruby version of Recursive Averages (http://www.codewars.com/kata/recursive-averages).
Modify the Array class to include an average method. The method give the average value of the items it contains. For example:
[1,2,3].average() #=> 2
But wait, there's more! If any item in the array is also an array, the method should calculate that average first, like so:
[1,2,[2,4]].average() #=> 2
The method should first average [2,4] into 3, and then average the resulting [1,2,3] into 2.
One more caveat: the method should attempt to work with non-numbers:
[1,2,'3 doors down'].average() #=> 2 where "3 doors down" == 3
[0.4, '1.6'].average() #=> 1 where '1.6' == 1.6
Algorithms
Similar Kata:
Stats:
Created | May 25, 2015 |
Published | May 25, 2015 |
Warriors Trained | 737 |
Total Skips | 19 |
Total Code Submissions | 3573 |
Total Times Completed | 312 |
JavaScript Completions | 312 |
Total Stars | 27 |
% of votes with a positive feedback rating | 90% of 90 |
Total "Very Satisfied" Votes | 75 |
Total "Somewhat Satisfied" Votes | 12 |
Total "Not Satisfied" Votes | 3 |