Skip to content

Commit d072ab1

Browse files
author
Miles Hinchliffe
committed
Create columns array
1 parent 86cc34a commit d072ab1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/lib/components/data-vis/table/Table.svelte

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,33 @@
1111
1212
let localCopyOfData = $state([...data]);
1313
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+
1441
const metrics = Object.keys(localCopyOfData[0]).slice(
1542
1,
1643
localCopyOfData[0].length,

0 commit comments

Comments
 (0)