문자열 my_string
과 정수 배열 indices
가 주어질 때, my_string
에서 indices
의 원소에 해당하는 인덱스의 글자를 지우고 이어 붙인 문자열을 return 하는 solution 함수를 작성해 주세요.
indices
의 길이 < my_string
의 길이 ≤ 100my_string
은 영소문자로만 이루어져 있습니다indices
의 원소 < my_string
의 길이indices
의 원소는 모두 서로 다릅니다.my_string | indices | result |
---|---|---|
"apporoograpemmemprs" | [1, 16, 6, 15, 0, 10, 11, 3] | "programmers" |
function solution(my_string, indices) {
let answer = my_string.split("");
for(let i = 0; i < indices.length; i++){
answer[indices[i]] = 0;
}
answer = answer.filter((el) => {
return el !== 0;
})
answer = answer.join("");
return answer;
function solution(my_string, indices) {
let answer = my_string.split("");
for(let i = 0; i < indices.length; i++){
delete answer[indices[i]];
}
return answer = answer.join("");
}
delete 개지린다..