functionpowerset(arr) {let answer = [[]];for (constnof arr) {consttemp= [];for (constelof answer) {constnext= [...el, n];temp.push(next); }answer.push(...temp); }return answer;}// Do not edit the line below.exports.powerset = powerset;
simpler
functionpowerset(arr) {let answer = [[]];for (constnof arr) {constanswerLenBeforeThisIter=answer.length;for (let i =0; i < answerLenBeforeThisIter; i++) {answer.push(answer[i].concat(n)); } }return answer;}// Do not edit the line below.exports.powerset = powerset;