Published on 08 October 2021 (Updated: 08 October 2021)

Welcome to the Josephus Problem in Javascript page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

constjosephus=(n,k)=>{if(n==1)return1;elsereturn((josephus(n-1,k)+k-1)%n)+1;};constusage="Usage: please input the total number of people and number of people to skip.";constn=parseInt(process.argv[2]);constk=parseInt(process.argv[3]);if(!n||!k||typeofn!=="number"||typeofk!=="number"){returnconsole.log(usage);}console.log(josephus(n,k));