Multi-level filtering and data aggregation using higher-order functions
JavaScript
Hard
functions
Task «Multi-level filtering and data aggregation using higher-order functions»
Write a function `processData` that takes an array of objects (each object contains fields `category`, `value`, `active`), and two integers `minValue` and `maxValue`. The function should filter objects where `active === true` and `value` is in the range [minValue, maxValue] (inclusive), then group them by `category`, for each group calculate the arithmetic mean of `value` (rounded to two decimal places), and sort the groups in descending order of the average value. Return an array of strings in the format "category: average".
Input Format
A string with a JSON array of objects, then two integers (minValue and maxValue) separated by a space.
Output Format
Array of strings, each string in the format "category: average" (without extra spaces). If there are no matching objects, return an empty array [].
Examples
Example 1
INPUT
123
OUTPUT
main.js