Average Value of Even Numbers Divisible by Three

Easy
12
72.2% Acceptance

In this lab, you will be challenged to create a function that calculates the average value of even numbers within an integer array nums containing positive integers. The function should return the average value of all even integers that are divisible by 3. Remember that the average of n elements is the sum of the n elements divided by n and rounded down to the nearest integer.

Function Signature

/** * @param {number[]} nums * @return {number} */ var averageValue = function(nums) { };

Examples

  • Input: nums = [1,3,6,10,12,15] Output: 9 Explanation: 6 and 12 are even numbers that are divisible by 3. (6 + 12) / 2 = 9.

  • Input: nums = [1,2,4,7,10] Output: 0 Explanation: There is no single number that satisfies the requirement, so return 0.

Constraints

  • 1 <= nums.length <= 1000
  • 1 <= nums[i] <= 1000

Challenges

  1. Implement the given function averageValue.
  2. Test the function for a few sample inputs and compare the result with the expected output.

Tips

  • Export the averageValue function and any other required variables or functions.
  • Make use of ESM import/export everywhere.

Good luck and happy coding!