[260204] 데이터 카테고리별 분리
This commit is contained in:
15
data/index.js
Normal file
15
data/index.js
Normal file
@@ -0,0 +1,15 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user