JavaScript solution
javascript\n/**\n * @param {number[]} A\n * @param {number} K\n * @return {number}\n */\nvar largestSumAfterKNegations = function(A, K) {\n  A.sort((a, b) => a 
```javascript\n/**\n * @param {number[]} A\n * @param {number} K\n * @return {number}\n */\nvar largestSumAfterKNegations = function(A, K) {\n  A.sort((a, b) => a - b);\n  for (let i = 0; i < A.length && K > 0 && A[i] < 0; i++, K--) A[i] = -A[i];\n  if (K > 0 && K % 2 == 1) {\n    const minI = A.reduce((min, cur, i) => (cur < A[min] ? i : min), 0);\n    A[minI] = -A[minI];\n  }\n  return A.reduce((acc, cur) => acc + cur);\n};\n```
['JavaScript']