DataviewJS Sorting Acting Weird

What I’m trying to do

Trying to sort my dataviewjs query by modified date

Things I have tried

const fileName = dv.current().file.name;
const match = fileName.match(/(\d{4})-W(\d{2})/);

if (match) {
    const [_, year, week] = match;
    const targetWeek = parseInt(week, 10);
    const targetYear = parseInt(year, 10);

    const filesInSameWeek = dv.pages()
	    .where(p => {
	        const modDate = new Date(p.file.mtime);
	        const modWeek = Number(moment(modDate).format('W'));
	        const modYear = Number(moment(modDate).format('YYYY'));
	
	        return modWeek === targetWeek && modYear === targetYear;
	    })
	    .sort((a, b) => {
		    dv.span(b);
		    
		    return new Date(a.mtime) - new Date(b.mtime)
		});

    dv.table(["File", "Modified"], filesInSameWeek.map(f => [f.file.name, f.file.mtime]));
} else {
    dv.paragraph("Current file name does not match the expected format YYYY-WWW.");
}

Result of this query is strange. a contains the expected files, but b contains numbers.
B follows the following pattern: 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, … and so on

Question

Why is b (within the sort) not a file? why is it these single digit numbers? almost like an index or something? How do I sort if not this way?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.