프로그래머스(JavaScript)/Lv0
[프로그래머스 : 코딩 기초 트레이닝]Lv0. 글자 지우기(JavaScript)
지미지민
2024. 3. 12. 21:51
💜 코드
function solution(my_string, indices) {
let str = '';
for(let i=0; i<my_string.length; i++){
if(!indices.includes(i)){
str+= my_string[i];
}
}
return str;
}
💜 실행 결과
💜 다른 사람의 풀이
function solution(my_string, indices) {
const copy = [...my_string]
for (let i = 0; i < indices.length; i++){
copy.splice(indices[i], 1, '')
}
return copy.filter((v)=>v).join('')
}