공주 구하기

WooBuntu·2021년 2월 23일
0

JS 90제

목록 보기
24/33
  • 내 풀이
const solution = (total, target) => {
  total = Array(total)
    .fill(null)
    .map((v, i) => i + 1);
  while (total.length > 1)
    for (let i = 0; i < target; i++)
      i == target - 1 ? total.shift() : total.push(total.shift());

  return total[0];
};
const result = solution(8, 3);
console.log(result);

0개의 댓글