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);