Find occurrence of a sub string
by Arvind Pal
JavaScript
let longStr="lorlie loledlo";
let smallStr ="lo";
function countOccurance(long, small){
let count =0;
for(let i=0; i<long.length;i++){
for(j=0;j<small.length;j++){
console.log(long[i+j], small[j])
if(long[i+j]!==small[j]){
break;
}
if(j===small.length-1){
count++
}
}
}
return count
}
console.time("start")
console.log(countOccurance(longStr, smallStr));
console.timeEnd("start")