subsets

    0

    0

    The code below prints the following JSON:

    [ { "id":1, "name":"one"}, { "id":2, "name":"two"}, { "id":3, "name":"three"} ]

    The code above creates an array of objects and prints each object to the console. The first object in the array is an empty array, and the second object in the array has one entry, which is the string "one". The third object in the array has two entries, which is the string "two" and the string "three".

    var subsets = function(nums) {
        let res = [[]];
    
        for (let i = 0; i < nums.length; i++) {
            let len = res.length;
            for (let j = 0; j < len; j++) {
                res.push([...res[j], nums[i]]);
            }
        }
    
        return res
    }
    
    
    const nums = readline().split(" ").map((n) => parseInt(n, 10));
    
    function printArray(arr) {
      console.log(JSON.stringify(arr).replace(/,\s*/g, ","));
    }
    
    printArray(subsets(nums));
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.