« get me outta code hell

http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/pickers.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/pickers.js')
-rw-r--r--src/pickers.js10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/pickers.js b/src/pickers.js
index ee886bc..2f44630 100644
--- a/src/pickers.js
+++ b/src/pickers.js
@@ -27,9 +27,13 @@ function makeShufflePlaylistPicker(grouplike) {
   const flatGroup = flattenGrouplike(grouplike)
 
   return function() {
-    const index = Math.floor(Math.random() * flatGroup.items.length)
-    const picked = flatGroup.items[index]
-    return picked
+    if (flatGroup.items.length) {
+      const index = Math.floor(Math.random() * flatGroup.items.length)
+      const picked = flatGroup.items[index]
+      return picked
+    } else {
+      return null
+    }
   }
 }