7 kyu

The mean of two means

922 of 1,685smarthutza

Description:

Write a function that takes as parameters an array (arr) and 2 integers (x and y). The function should return the mean between the mean of the the first x elements of the array and the mean of the last y elements of the array.

The mean should be computed if both x and y have values higher than 1 but less or equal to the array's length. Otherwise the function should return -1.

Examples

[1, 3, 2, 4], 2, 3 => should return 2.5

because: the mean of the the first 2 elements of the array is (1+3)/2=2 and the mean of the last 3 elements of the array is (4+2+3)/3=3 so the mean of those 2 means is (2+3)/2=2.5.

[1, 3, 2, 4], 1, 2 => should return -1

because x is not higher than 1.

[1, 3, 2, 4], 2, 8 => should return -1

because 8 is higher than the array's length.

Arrays
Fundamentals

Stats:

CreatedNov 29, 2016
PublishedNov 29, 2016
Warriors Trained2735
Total Skips33
Total Code Submissions6978
Total Times Completed1685
JavaScript Completions724
Crystal Completions10
Python Completions922
Ruby Completions94
Total Stars29
% of votes with a positive feedback rating90% of 385
Total "Very Satisfied" Votes319
Total "Somewhat Satisfied" Votes52
Total "Not Satisfied" Votes14
Total Rank Assessments12
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • smarthutza Avatar
  • SagePtr Avatar
  • GiacomoSorbi Avatar
  • suic Avatar
  • hobovsky Avatar
  • ejini战神 Avatar
  • farhanaditya Avatar
Ad