Simple JavaScript Solution
Code\njavascript []\n/**\n * @param {number[]} nums\n * @param {number} k\n * @param {number} x\n * @return {number[]}\n */\nvar findXSum = function (nums, k, x
# Code\n```javascript []\n/**\n * @param {number[]} nums\n * @param {number} k\n * @param {number} x\n * @return {number[]}\n */\nvar findXSum = function (nums, k, x) {\n  let result = [];\n\n  for (let i = 0; i <= nums.length - k; i++) {\n    let temp_arr = [...nums].slice(i, i + k);\n    let count = {};\n\n    for (let j = 0; j < temp_arr.length; j++) {\n      const num = temp_arr[j];\n      count[num] = (count[num] || 0) + 1;\n    }\n\n    console.log(count);\n\n    const sum = Object.entries(count)\n      .sort((a, b) => {\n        if (b[1] !== a[1]) return b[1] - a[1];\n        return b[0] - a[0];\n      })\n      .slice(0, x)\n      .reduce((prev, curr) => prev + curr[0] * curr[1], 0);\n\n    result.push(sum);\n  }\n\n  return result;\n};\n```
['JavaScript']