Dataview product comparison

@ryan_thomas
I love this solution. It saves plenty of code if one wants to do it the regular way, and then transpose it, from rows to columns.

This is what I usually do:

ipad-tablet-rows.md


feature:: Brand
value:: Apple

feature:: Model
value:: iPad 11-inch (M4)

feature:: Price
value:: $999

feature:: OS
value:: iOS 18

feature:: CPU
value:: M4 chip

feature:: RAM
value:: NA

feature:: Storage
value:: 256 GB

lenovo-tablet-rows.md

feature:: Brand
value:: Lenovo

feature:: Model
value:: Lenovo Yoga Tab Plus

feature:: Price
value:: $699

feature:: OS
value:: Android 15

feature:: CPU
value:: Snapdragon 8 Gen 3

feature:: RAM
value:: Up to 16 GB

feature:: Storage
value:: Up to 512 GB

Then, after running the script (below), I get this table grouped by rows.

Code

```dataviewjs
const currentFileLink = dv.current().file.link;
let pages = dv.pages()
	.where(page => page.file.inlinks 
		&& page.file.inlinks.includes(currentFileLink) 
		&& page.feature);

const flattened = [];

pages
	.where(p => p.feature && p.value) 
	.map(p => {
		for (let i = 0; i < p.feature.length; i++) {
			flattened.push(
				{
				 feature: p.feature[i], 
				 value: p.value[i],
				 filename: p.file.name
				 }
			)
		}	
})

let dataGroups = dv.array(flattened)
	.groupBy(p => p.filename)
	.sort(p => p.filename, 'asc')

for (let g of dataGroups) {
	dv.header(5, g.key)
	dv.table(['Feature', 'value'], 
		g.rows
			// .sort(p => p.feature, 'asc')
			 .map(a => [
						 a.feature, 
						 a.value
						]
			)
	)
}
```

The transpose operation is done by means of the function described in this post: How to switch column and row text using dataviewjs - #2 by justdoitcc