UNIVERSAL Solution To Solve Any N-Sum Problem Using Recursion
javascript\nvar fourSum = function(nums, target) {\n    nums.sort((a, b) => a - b);\n    const result = [];\n    \n    // k represents N-sum, \n    // if k = 3 
```javascript\nvar fourSum = function(nums, target) {\n    nums.sort((a, b) => a - b);\n    const result = [];\n    \n    // k represents N-sum, \n    // if k = 3 : 3Sum, if k = 4 : 4Sum, if k = 5, 5Sum; \n    function recurse(arr, tar, res, k) {\n        if(k === 2) {\n            twoSum(arr, tar, res);\n            return;\n        }\n        \n        for(let i = 0; i < arr.length; i++) {\n            while(arr[i] === arr[i-1]) i++;\n            recurse(arr.slice(i+1), tar - arr[i], [...res, arr[i]], k-1);\n        }\n    }\n    \n    function twoSum(arr, tar, res) {\n        let low = 0, high = arr.length-1;\n        \n        while(low < high) {\n            const sum = arr[low] + arr[high];\n            if(sum === tar)  {\n                result.push([...res, arr[low], arr[high]]);\n                while(arr[low] === arr[low+1]) low++;\n                while(arr[high] === arr[high-1]) high--;\n                low++;\n                high--;\n            } else if(sum < tar) low++;\n            else high--;\n        }\n    }\n    \n    recurse(nums, target, [], 4)\n    return result\n};\n```
['JavaScript']