#JavaScript and Typescript
\n# Code\n\nfunction largestSumAfterKNegations(nums: number[], k: number): number {\n\nconst arr= nums.sort((a,b)=>a-b);\nlet index=0;\nwhile(k!=0){\n    arr[in
\n# Code\n```\nfunction largestSumAfterKNegations(nums: number[], k: number): number {\n\nconst arr= nums.sort((a,b)=>a-b);\nlet index=0;\nwhile(k!=0){\n    arr[index]*=-1;\n    if(arr[index]>arr[index+1]){\n        index+=1;\n    }\n    k-=1;\n}\nreturn arr.reduce((prev,curr)=>prev+curr,0)\n\n\n};\n```
['TypeScript']