문제 설명

문자열 my_string과 정수 배열 indices가 주어질 때, my_string에서 indices의 원소에 해당하는 인덱스의 글자를 지우고 이어 붙인 문자열을 return 하는 solution 함수를 작성해 주세요.

제한사항

  • 1 ≤ indices의 길이 < my_string의 길이 ≤ 100
  • my_string은 영소문자로만 이루어져 있습니다
  • 0 ≤ indices의 원소 < my_string의 길이
  • indices의 원소는 모두 서로 다릅니다.

입출력 예

my_stringindicesresult
"apporoograpemmemprs"[1, 16, 6, 15, 0, 10, 11, 3]"programmers"

풀이

풀이 1

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;

풀이 2

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 개지린다..

profile
개인 이력, 포폴 관리 및 기술 블로그 사이트 👉 https://aimzero-web.vercel.app/

0개의 댓글