Another JavaScript approach for beginners
The idea is very straight forward.\n1. create all the possible topping cost combinations\n2. combine baseCosts + all the possible topping cost array values\n3. 
The idea is very straight forward.\n1. create all the possible topping cost combinations\n2. combine baseCosts + all the possible topping cost array values\n3. find the closest value to target\n\n```\nvar closestCost = function(baseCosts, toppingCosts, target) {\n\t// 1. create all the possible topping cost combinations\n    const check = (i) => {\n        let a = toppingCosts[i];\n        let b = a * 2;\n        let c = [];\n        if (i + 1 < toppingCosts.length) {\n            c = check(i+1);\n        }\n        let out = [a, b, ...c];\n        for (let cc of c) {\n            out.push(a + cc);\n            out.push(b + cc);\n        }\n\n        return out;\n    };\n\n    let t = check(0);\n\n\t// 2. combine baseCosts + all the possible topping cost array values\n    let out = [];\n    for (let b of baseCosts) {\n        out.push(b);\n        for (let tt of t) {\n            out.push(b + tt);\n        }\n    }\n\t\n\t// 3. find the closest value to target\n    let val = 0;\n    let dif = Infinity;\n\n    for(let i = 0; i < out.length; i++) {\n        let d = Math.abs(target - out[i]);\n        if (d < dif) {\n            dif = d;\n            val = out[i];\n        }\n    }\n\n    return val;\n};
[]