就一点正则用法

来源:7-5 最大矩阵-代码实操(2)

_玲

2019-03-10

能想到的问题,都被老师补全了。
不开森…

  // 把二位数组重新表达,把相邻的1提取出来(起始点+截止点)
  arr = arr.map(item => {
    let str = item.join('')
    let r = reg.exec(str)
    let rs = []
    while (r) {
     // 这里可以用reg.lastIndex - 1 === r.index + r[0].length - 1
      rs.push([r.index, r.index + r[0].length - 1]) 
      r = reg.exec(str)
    }
    return rs
  })

reg.lastIndex:The index at which to start the next match. If g is absent, this will always be 0.

写回答

1回答

快乐动起来呀

2019-03-10

哈哈,你已经很不错了,真的是用心在学习,等我的奖励吧

1
1
_玲
?哈哈
2019-03-10
共1条回复

JavaScript版 数据结构与算法

填补前端同学的算法短板,掌握面试中最常见的算法与数据结构

2467 学习 · 395 问题

查看课程