JSFiddle - React, Tailwind, and code Playground

by Simon Herteby

JavaScript

const input = [{
    isFolder: true,
    name: "Cats",
    content: [{
        isfolder: false,
        name: "cat1.jpg",
        size: 113
      },
      {
        isFolder: false,
        name: "cat2.jpg",
        size: 415
      },
      {
        isFolder: false,
        name: "cat3.jpg",
        size: 265
      }
    ]
  },
  {
    isFolder: true,
    name: "Dogs",
    content: [{
        isFolder: false,
        name: "dog1.jpg",
        size: 634
      },
      {
        isFolder: false,
        name: "dog2.jpg",
        size: 99
      },
      {
        isFolder: false,
        name: "dog3.jpg",
        size: 453
      },
      {
        isFolder: true,
        name: "Puppies",
        content: [{
            isFolder: false,
            name: "puppy1.jpg",
            size: 634
          },
          {
            isFolder: false,
            name: "puppy2.jpg",
            size: 99
          },
          {
            isFolder: false,
            name: "puppy3.jpg",
            size: 453
          }
        ]
      }
    ]
  }
]

function totalSize(items) {
  //TODO
}

document.write(totalSize(input))

/*
The totalSize function should return the sum of all the file sizes

Preferably do it in a pure functional style, without mutation, for/while-loops or "forEach"

You can use Lodash or Underscore if you want

Hint: You may want totalSize to call itself

*/