Intermediate Level


I am trying examples on this platform

But i dont understand the solution of this problem. I know how concat, map and reduce methods work but still i dont understand the logic of the solution. How can i improve the understanding to next level?

practice doing algorithms

break down that line


many things you can do

const powerset = arr => arr.reduce((a, v) => a.concat( => [v].concat(r))), [[]]);

to start I would break this donw in loggable steps

function powerset (arr) {
  return arr.reduce((a, v) => a.concat( => [v].concat(r))), [[]]);

and then again

function reduceCallback(a, v) {
  return a.concat( => [v].concat(r)))
function powerset (arr) {
  return arr.reduce(reduceCallback, [[]]);

and again

function reduceCallback(a, v) {
  function mapCallback(r) {
    return [v].concat(r)
  return a.concat(

function powerset(arr) {
  return arr.reduce(reduceCallback, [
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.