Closed zhanhongtao closed 7 years ago
需求如下图:
function log (start, end) { console.log(`${end.id !== start.id ? `${start.id}-${end.id}` : `${start.id}`}: ${start.name}`) } function handler (list) { if (list.length === 0) return let start = list[0] let end = start for (let i = 1; i <= list.length; ++i) { let item = list[i] if ( item && item.id === end.id + 1 && item.name === end.name ) { end = item } else { log(start, end) start = end = item } } }
需求如下图: