[JavaScript] Simple Backtracking
Time: O(N * 3^M)  where N is size of baseCosts and M is size of toppingCosts\nSpace: O(M)\njavascript\nvar closestCost = function(baseCosts, toppingCosts, targe
Time: `O(N * 3^M)`  where `N` is size of `baseCosts` and `M` is size of `toppingCosts`\nSpace: `O(M)`\n```javascript\nvar closestCost = function(baseCosts, toppingCosts, target) {\n    if(baseCosts.includes(target)) return target;\n    \n    let result = baseCosts[0];\n    baseCosts.forEach(n => backtrack(0, n));\n    return result;\n        \n    function backtrack(idx, sum) {\n        const currDiff = Math.abs(result - target);\n        const newDiff = Math.abs(sum - target);\n        \n        if(newDiff < currDiff) result = sum;\n        else if(newDiff === currDiff) result = Math.min(result, sum);\n        if(idx === toppingCosts.length || sum > target) return;\n\n        for(let i = 0; i < 3; i++) {\n            backtrack(idx+1, sum + (toppingCosts[idx] * i));\n        }\n    }\n};\n```
['Backtracking', 'JavaScript']