Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- EFCore
- mac
- scanner
- Config
- ViewModel
- ORM
- JSON
- ""+n
- DbSave
- inserttrigger
- .net
- c#
- JavaScript
- extjs
- 자원정리
- dbContext
- c#코딩의기술실전편
- Store
- React
- intellij
- 코드프로그래머스
- extraParams
- lazy loading
- error
- 상속
- minimalAPI
- LINQ
- 명시적외래키
- Request
- vscode
Archives
- Today
- Total
ejyoo's 개발 노트
[JavaScript] 중복 제거 코드 본문
/**
* 중복 데이터에서 uniquedata만 추출하는 함수
* @param {*} duplicateItems 중복데이터 목록
* @param {*} customFunc 유일 데이터 추출하기 위한 커스텀 함수
* @returns
*/
convertUniqueDatas: function (duplicateItems, customFunc) {
if (!Array.isArray(duplicateItems)) {
throw new Error("DuplicateItems must be an array.");
}
var uniqueItems = undefined;
if (typeof customFunc === 'function') {
uniqueItems = [...new Set([].concat(...duplicateItems.map(item => {
try {
return customFunc(item);
} catch (e) {
console.error("Error running customFunc.", e);
return item;
}
})))];
} else {
uniqueItems = [...new Set([].concat(...duplicateItems.map(item => {
return item;
})))];
}
return uniqueItems;
}