MCPcopy Create free account
hub / github.com/develop202/migu_video / uniqueData

Function uniqueData

utils/fetchList.js:139–187  ·  view source on GitHub ↗
(liveList)

Source from the content-addressed store, hash-verified

137
138// 对data的dataList去重
139function uniqueData(liveList) {
140
141 const allItems = []
142 // 提取全部dataList
143 liveList.forEach(category => {
144 category.dataList.forEach(program => {
145
146 allItems.push({
147 ...program,
148 categoryName: category.name
149 })
150 })
151
152 })
153
154 // 使用set确保唯一
155 const set = new Set()
156 // 保存唯一的数据
157 const uniqueItem = []
158
159 allItems.forEach(item => {
160 // set用来确定已经出现过
161 if (!set.has(item.name)) {
162 set.add(item.name)
163 uniqueItem.push(item)
164 }
165 })
166
167 const categoryMap = []
168
169 // 清空原dataList内容
170 liveList.forEach(live => {
171 live.dataList = []
172 categoryMap[live.name] = []
173 })
174
175 // 去除添加字段,根据分类填充内容
176 uniqueItem.forEach(item => {
177 const { categoryName, ...program } = item
178 categoryMap[categoryName].push(program)
179 })
180
181 // liveList赋值
182 liveList.forEach(live => {
183 live.dataList = categoryMap[live.name]
184 })
185
186 return liveList
187}
188
189export { cateList, dataList, delay }

Callers 1

dataListFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected