사랑하애오

솔루션

const solution = (cipher, code) => {
  const str = [...cipher];
  const answer = str.reduce(
    (a, c, i) => ((i + 1) % code === 0 ? a + c : a),
    ""
  );
  console.log(answer);

  return answer;
};

 

솔루션

const solution = (cipher, code) => {
  const answer = [];
  for (let i = code - 1; i < cipher.length; i += code) {
    answer.push(cipher[i]);
  }
  console.log(answer.join(""));

  return answer.join("");
};

 

솔루션

const solution = (cipher, code) => {
  const answer = cipher
    .split("")
    .filter((v, i) => (i + 1) % code === 0)
    .join("");
  console.log(answer);

  return answer;
};
profile

사랑하애오

@사랑하애

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!