文章 评论 浏览 30
class myString extends String { myIndexOf(str: string) { const O = Object(this); const reg = new RegExp(str, 'g'); const res = reg.exec(O); if (res) { return res.index; } return -1; } } const stringTest = new myString('abcdefg'); console.log(stringTest.myIndexOf('23')); console.log(stringTest.myIndexOf('cde')); export {};
# 跑路
TIL
文章 0 评论 0
接受
第 151 题:用最简洁代码实现 indexOf 方法?