Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo-mod-jslibs-dist.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'popperjs/package/lib/utils/uniqueBy.js.flow')
-rw-r--r--popperjs/package/lib/utils/uniqueBy.js.flow14
1 files changed, 14 insertions, 0 deletions
diff --git a/popperjs/package/lib/utils/uniqueBy.js.flow b/popperjs/package/lib/utils/uniqueBy.js.flow
new file mode 100644
index 0000000..0f79ae9
--- /dev/null
+++ b/popperjs/package/lib/utils/uniqueBy.js.flow
@@ -0,0 +1,14 @@
+// @flow
+
+export default function uniqueBy<T>(arr: Array<T>, fn: T => any): Array<T> {
+ const identifiers = new Set();
+
+ return arr.filter(item => {
+ const identifier = fn(item);
+
+ if (!identifiers.has(identifier)) {
+ identifiers.add(identifier);
+ return true;
+ }
+ });
+}