File tree Expand file tree Collapse file tree 1 file changed +26
-10
lines changed
Expand file tree Collapse file tree 1 file changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -86,24 +86,40 @@ function hasFiles(pathParts) {
8686
8787// Count items in path
8888function countItemsFromTree ( pathParts ) {
89- const items = getFolderFromTree ( pathParts ) ;
90- if ( ! items ) return 0 ;
89+ if ( pathParts . length === 0 ) return 0 ;
9190
92- let count = 0 ;
91+ const platformName = pathParts [ 0 ] ;
92+ const tree = state . treeData [ platformName ] ;
93+
94+ if ( ! tree ) return 0 ;
95+ if ( pathParts . length === 1 ) {
96+ // Counting items in platform root
97+ return countRecursive ( tree ) ;
98+ }
99+
100+ // Find the specific node
101+ const node = findInTree ( tree , pathParts , 1 ) ;
102+ if ( ! node ) return 0 ;
103+
104+ // If this node itself has files, it's 1 item
105+ if ( node . has_files ) return 1 ;
106+
107+ // Otherwise count children
108+ if ( ! node . children ) return 0 ;
109+ return countRecursive ( node . children ) ;
93110
94111 function countRecursive ( nodes ) {
95- for ( const node of nodes ) {
96- if ( node . has_files ) {
112+ let count = 0 ;
113+ for ( const n of nodes ) {
114+ if ( n . has_files ) {
97115 count ++ ;
98116 }
99- if ( node . children ) {
100- countRecursive ( node . children ) ;
117+ if ( n . children ) {
118+ count += countRecursive ( n . children ) ;
101119 }
102120 }
121+ return count ;
103122 }
104-
105- countRecursive ( items ) ;
106- return count ;
107123}
108124
109125// Fetch file contents from GitHub (only when viewing a problem)
You can’t perform that action at this time.
0 commit comments