« get me outta code hell

Don't crash when calling countTotalItems on tracks - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2019-08-08 19:35:18 -0300
committerFlorrie <towerofnix@gmail.com>2019-08-08 19:35:18 -0300
commit7552ecaecb4d9c6ca786422ec955be7eb3b1ca71 (patch)
tree2b0f5a59aa5e85866c1c1f90ef7435ebd59b322f
parent8c9d501ea0d527ec8ea5743c42f37725669a71f1 (diff)
Don't crash when calling countTotalItems on tracks
-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) {