(itemsSet, getKey, condition)
| 283 | * @returns {string[][]} list of common items |
| 284 | */ |
| 285 | const popCommonItems = (itemsSet, getKey, condition) => { |
| 286 | /** @type {Map<string, string[]>} */ |
| 287 | const map = new Map(); |
| 288 | |
| 289 | for (const item of itemsSet) { |
| 290 | const key = getKey(item); |
| 291 | if (key) { |
| 292 | let list = map.get(key); |
| 293 | if (list === undefined) { |
| 294 | /** @type {string[]} */ |
| 295 | list = []; |
| 296 | map.set(key, list); |
| 297 | } |
| 298 | list.push(item); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | /** @type {string[][]} */ |
| 303 | const result = []; |
| 304 | |
| 305 | for (const list of map.values()) { |
| 306 | if (condition(list)) { |
| 307 | for (const item of list) { |
| 308 | itemsSet.delete(item); |
| 309 | } |
| 310 | result.push(list); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | return result; |
| 315 | }; |
| 316 | |
| 317 | /** |
| 318 | * @param {string[]} itemsArr array of items |
no outgoing calls
no test coverage detected
searching dependent graphs…