프로그래머스 다른 사람의 풀이 자바스크립트

버건디·2023년 4월 26일
0

프로그래머스

목록 보기
43/66

문제 풀이

- 내 풀이

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("");
}
profile
https://brgndy.me/ 로 옮기는 중입니다 :)

0개의 댓글

관련 채용 정보