프로그래머스
[프로그래머스] 둘만의 암호
so_yeon_-
2024. 12. 6. 19:50
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점