aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/utils.js')
-rw-r--r--src/lib/utils.js5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/lib/utils.js b/src/lib/utils.js
index f55b47b6..5303ec35 100644
--- a/src/lib/utils.js
+++ b/src/lib/utils.js
@@ -281,3 +281,8 @@ export function shuffleArray(array) {
[array[i], array[j]] = [array[j], array[i]];
}
}
+
+ export let closest = (a, n) =>
+ a.reduce((prev, curr) =>
+ Math.abs(curr - n) < Math.abs(prev - n) ? curr : prev
+ );