Browse Source

add unique array fn to util.js

ameba23 2 years ago
parent
commit
b1011feb0c
No known key found for this signature in database
1 changed files with 6 additions and 1 deletions
  1. 6
    1
      util.js

+ 6
- 1
util.js View File

@@ -18,4 +18,9 @@ function logCpuMemory (id) {
18 18
   }
19 19
 }
20 20
 
21
-module.exports = { virtualize, normalize, logCpuMemory }
21
+function uniq (array) {
22
+  if (!Array.isArray(array)) array = [array]
23
+  return Array.from(new Set(array))
24
+}
25
+
26
+module.exports = { virtualize, normalize, logCpuMemory, uniq }