From 7552ecaecb4d9c6ca786422ec955be7eb3b1ca71 Mon Sep 17 00:00:00 2001 From: Florrie Date: Thu, 8 Aug 2019 19:35:18 -0300 Subject: Don't crash when calling countTotalItems on tracks --- playlist-utils.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'playlist-utils.js') 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) { -- cgit 1.3.0-6-gf8a5