문제 풀이
- 내 풀이
function solution(s, skip, index) {
var answer = "";
const alphabet = Array.from({ length: 26 }, (v, i) =>
String.fromCharCode(i + 97)
);
[...s].forEach((str) => {
let idx = index;
let plusAlphabet;
let strIndex = alphabet.indexOf(str);
while (idx > 0) {
strIndex += 1;
if (strIndex > 25) {
strIndex = 0;
}
plusAlphabet = alphabet[strIndex];
if (skip.includes(plusAlphabet)) {
continue;
} else {
idx--;
}
}
answer += plusAlphabet;
});
return answer;
}
- 다른 사람 풀이
function solution(s, skip, index) {
const alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
"u", "v", "w", "x", "y", "z"].filter(c => !skip.includes(c));
return s.split("").map(c => alphabet[(alphabet.indexOf(c) + index) % alphabet.length]).join("");
}