Files
zenn.inventory/data/index.js

15 lines
495 B
JavaScript

import games from './games.js';
import tech from './tech.js';
import furniture from './furniture.js';
// 1. 모든 배열을 하나로 합치기
const allData = [...games, ...tech, ...furniture];
// 2. 날짜순(최신순) 정렬: createdAt이 같은 경우 id로 2차 정렬
const products = allData.sort((a, b) => {
const dateDiff = new Date(b.createdAt) - new Date(a.createdAt);
if (dateDiff !== 0) return dateDiff;
return b.id.localeCompare(a.id);
});
export default products;