const str = 'eqwe1231abc1qweq'
const tar = 'abc'
// function myIndexOf(big, small) {
// const reg = new RegExp(small)
// const res = reg.exec(big)
// if (res) {
// return res.index
// } else {
// return -1
// }
// }
// console.log(myIndexOf(str,tar))
function getIndex(big, small) {
let bigLen = big ? big.length : 0
let smallLen = small ? small.length : 0
if (smallLen > bigLen) {
return -1
}
let res = -1
for(let i = 0; i <= bigLen - smallLen; i++) {
const sub = big.substr(i, smallLen)
if(sub === small) {
res = i
break;
}
}
return res
}
console.log(getIndex(str,tar))
console