« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--playlist-utils.js15
1 files changed, 7 insertions, 8 deletions
diff --git a/playlist-utils.js b/playlist-utils.js
index d2a0bad..6119bc3 100644
--- a/playlist-utils.js
+++ b/playlist-utils.js
@@ -177,17 +177,16 @@ function flattenGrouplike(grouplike) {
   }
 }
 
-function countTotalItems(grouplike) {
+function countTotalItems(item) {
   // Returns the total number of items in a grouplike, including items in any
   // descendant groups. Basically the same as flattenGrouplike().items.length.
 
-  return grouplike.items.map(item => {
-    if (isGroup(item)) {
-      return countTotalItems(item)
-    } else {
-      return 1
-    }
-  }).reduce((a, b) => a + b, 0)
+  if (isGroup(item)) {
+    return item.items.map(countTotalItems)
+      .reduce((a, b) => a + b, 0)
+  } else {
+    return 1
+  }
 }
 
 function shuffleOrderOfGroups(grouplike) {