무한루프 안에서 s안에 part가 있는지 indexOf를 사용하여 풀이
/**
* @param {string} s
* @param {string} part
* @return {string}
*/
var removeOccurrences = function(s, part) {
// 무한루프
while(true){
// part가 있는지 체크
const index = s.indexOf(part);
if(index === -1){
// 없다면 탈출
break;
} else {
// 있다면 빈 문자열로 교체
s=s.replace(part,'')
}
}
return s;
};
https://leetcode.com/problems/remove-all-occurrences-of-a-substring/