JavaScript Javascript recursion resetting the count

If you do not need count for a different purpose, then I suggest to delete the parameter count and just return the locale count.

function totalReports(object) {
    var count = 0;
    Object.keys(object).forEach(function (key) {
        if (object[key] && typeof object[key] === 'object') {
            if (object[key].type === 'file') {
                count++;
            }
            count += totalReports(object[key]);
        }
    });
    return count;
}

var jsonArray = { "parent": { "url": "parent.html", "name": "Parent", "children": [{ "type": "folder", "name": "Folder 1", "url": "folder1.html", "children": [{ "type": "file", "name": "File 1", "url": "folder1-file1.html", "children": [] }, { "type": "file", "name": "File 2", "url": "folder1-file2.html", "children": [] }, { "type": "file", "name": "File 2", "url": "folder1-file3.html", "children": [] }] }, { "type": "folder", "name": "Folder 2", "url": "folder2.html", "children": [] }, { "type": "folder", "name": "Folder 3", "url": "folder3.html", "children": [{ "type": "file", "name": "Folder3 File1", "url": "folder3-file1", "children": [] }, { "type": "folder", "name": "Folder3 Folder1", "url": "folder3-file1", "children": [{ "type": "folder", "name": "Folder3 Folder1 Folder1", "url": "folder3-folder1-folder1", "children": [{ "type": "file", "name": "Folder3 Folder1 Folder1 File1", "url": "folder3-folder1-folder1-file1", "children": [] }, { "type": "file", "name": "Folder3 Folder1 Folder1 File2", "url": "folder3-folder1-folder1-file2", "children": [] }] }] }] }] } },
    count = totalReports(jsonArray);

document.write(count);
Answer:1

I am trying to create a filtering for a Stapes object in RactiveJS, but it seem the two way binding is not responding correctly to the update. I can't work out what is going wrong where as I thought ...

I am trying to create a filtering for a Stapes object in RactiveJS, but it seem the two way binding is not responding correctly to the update. I can't work out what is going wrong where as I thought ...

I have a test.txt file that has two columns of data (x's and y's), eg: #test.txt 1 23 2 234 4 52 43 5 3 35 And a python program that reads in these values and stores them in x and y as so: #test.py ...

I have a test.txt file that has two columns of data (x's and y's), eg: #test.txt 1 23 2 234 4 52 43 5 3 35 And a python program that reads in these values and stores them in x and y as so: #test.py ...

  1. transfer array from php to javascript
  2. transfer array in java

I'm currently working on something that requires me to put the value of an input field as an object item. var test = { item1:{ subitem1: "", <------- This is the one I'm trying to fill ...

I'm currently working on something that requires me to put the value of an input field as an object item. var test = { item1:{ subitem1: "", <------- This is the one I'm trying to fill ...

I have a situation where I need to add a class to a table, but only if the table is inside a div with id 'mydiv' AND there is a row in table containing an <a href=...> element where the href ...

I have a situation where I need to add a class to a table, but only if the table is inside a div with id 'mydiv' AND there is a row in table containing an <a href=...> element where the href ...