두 문자열 s와 skip, 그리고 자연수 index가 주어질 때, 다음 규칙에 따라 문자열을 만들려 합니다. 암호의 규칙은 다음과 같습니다.
s | skip | index | result |
---|---|---|---|
"aukks" | "wbqd" | 5 | "happy" |
function solution(s, skip, index) {
let answer = '';
const alphabet = 'abcdefghijklmnopqrstuvwxyz';
const newAlphabet = [...alphabet].filter(a => ![...skip].includes(a));
for (const x of s) {
newAlphabet.forEach((s, i, arr) => s === x && (answer += arr[(i + index) % arr.length]))
}
return answer;
}
🤍 includes()
const arr = ['apple', 'banana', 'orange'];
console.log(arr.includes('orange')) // true
🤍 for...of
const iterable = [10, 20, 30];
for (let value of iterable) {
value += 1;
console.log(value); // 11, 21, 31
}