https://school.programmers.co.kr/learn/courses/30/lessons/155652
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
접근방법
s와 skip배열을 ASCII 코드 값으로 변환하여
s 배열의 각 문자가 skip배열에 포함되어 있으면 그대로 +1, skip배열에 포함되어있으면 realIndex를 증가시켜 index에 도달하도록 만든뒤 ASCII값을 문자로 반환하여 반환하였다.
제출
function solution(s, skip, index) {
var answer = '';
const shipList = skip.split("").map(item => item.charCodeAt(0));
answer = s.split("").reduce((result,item) => {
let temp = item.charCodeAt(0);
let realIndex = 0;
while(realIndex < index){
temp ++
if (temp > 122) temp = 97;
if(!shipList.includes(temp)){
realIndex ++
}
}
return result + String.fromCharCode(temp)
}, ""
)
return answer;
}
결과 : 100점
'프로그래머스' 카테고리의 다른 글
[프로그래머스] 가장 가까운 같은 글자 (0) | 2024.12.08 |
---|---|
[프로그래머스] 크기가 작은 부분 문자열 (0) | 2024.12.07 |
[프로그래머스] 카드 뭉치 (0) | 2024.12.05 |
[프로그래머스] 대충 만든 자판 (0) | 2024.12.04 |
[프로그래머스] 덧칠하기 (0) | 2024.12.03 |