summaryrefslogtreecommitdiff
path: root/source/helpers/get-items-between.ts
diff options
context:
space:
mode:
Diffstat (limited to 'source/helpers/get-items-between.ts')
-rw-r--r--source/helpers/get-items-between.ts9
1 files changed, 9 insertions, 0 deletions
diff --git a/source/helpers/get-items-between.ts b/source/helpers/get-items-between.ts
new file mode 100644
index 00000000..75221535
--- /dev/null
+++ b/source/helpers/get-items-between.ts
@@ -0,0 +1,9 @@
+/**
+Get the items between previous and current, both ends included. If `previous` is missing, start from 0
+*/
+export default function getItemsBetween<T>(items: T[], previous: T | undefined, current: T): T[] {
+ const start = previous ? items.indexOf(previous) : 0;
+ const end = items.indexOf(current);
+
+ return items.slice(Math.min(start, end), Math.max(start, end) + 1);
+}