aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/utils.js')
-rw-r--r--src/js/utils.js9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/js/utils.js b/src/js/utils.js
index dd1466df..2ec57a50 100644
--- a/src/js/utils.js
+++ b/src/js/utils.js
@@ -746,6 +746,15 @@ const utils = {
return array.filter((item, index) => array.indexOf(item) === index);
},
+ // Get the closest value in an array
+ closest(array, value) {
+ if (!utils.is.array(array) || !array.length) {
+ return null;
+ }
+
+ return array.reduce((prev, curr) => Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev);
+ },
+
// Get the provider for a given URL
getProviderByUrl(url) {
// YouTube