🐈
重複チェック&削除
console.time("isDuplicateIncludes")
const isDuplicateIncludes = ctx.participatingList.userList
.map(user => user.peerId)
.includes(payloadUserName.peerId)
console.timeEnd("isDuplicateIncludes")
console.log("isDuplicateIncludes 重複チェック", isDuplicateIncludes)
console.time("isDuplicateSome")
const isDuplicateSome = ctx.participatingList.userList.some(
user => user.peerId === payloadUserName.peerId
)
console.timeEnd("isDuplicateSome")
console.log("isDuplicateSome 重複チェック", isDuplicateSome)
function removeDuplicatePeerIds(data: UserListProps[]) {
const uniquePeerIds = new Set()
const filteredData = data.filter(item => {
if (!uniquePeerIds.has(item.peerId)) {
uniquePeerIds.add(item.peerId)
return true
}
return false
})
return filteredData
}
Discussion