File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
src/lib/components/data-vis/table Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 11
11
12
12
let localCopyOfData = $state ([... data]);
13
13
14
+ function hasUniqueValues (array , key ) {
15
+ const seen = new Set ();
16
+ for (const obj of array) {
17
+ if (seen .has (obj[key])) {
18
+ return false ; // Duplicate found
19
+ }
20
+ seen .add (obj[key]);
21
+ }
22
+ return true ; // All values are unique
23
+ }
24
+
25
+ $inspect (localCopyOfData[0 ]);
26
+
27
+ let columns = [];
28
+
29
+ for (const key in localCopyOfData[0 ]) {
30
+ // create a variable to store whether the key is unique or not
31
+ const keyIsUnique = hasUniqueValues (localCopyOfData, key);
32
+ console .log (keyIsUnique);
33
+
34
+ // for each one create an object and push it into the array
35
+ const columnObject = { key: key, isUnique: keyIsUnique };
36
+ columns .push (columnObject);
37
+ }
38
+
39
+ $inspect (" columns array is " , columns);
40
+
14
41
const metrics = Object .keys (localCopyOfData[0 ]).slice (
15
42
1 ,
16
43
localCopyOfData[0 ].length ,
You can’t perform that action at this time.
0 commit comments