Change:
```js function josephus(init, kill) { <del> var Josephus = { init: function(n) { this.head = {}; var current = this.head; for (var i = 0; i < n - 1; i++) { current.label = i + 1; current.next = { prev: current }; current = current.next; } current.label = n; current.next = this.head; this.head.prev = current; return this; }, kill: function(spacing) { var current = this.head; while (current.next !== current) { for (var i = 0; i < spacing - 1; i++) { current = current.next; } current.prev.next = current.next; current.next.prev = current.prev; current = current.next; } return current.label; } </del> <ins> const arr = Array.from(Array(init).keys()); let curr = -1 while (arr.length > 1) { curr = (curr + kill) % arr.length; arr.splice(curr, 1); curr--; </ins> } <del> return Josephus.init(init).kill(kill) </del> <ins> return arr[0]; </ins> } ```

Discussion:
<!-- NOTE: If you're reporting a security issue, don't create a GitHub issue. Instead, email We will look into it immediately. --Affected page Your code Expected behavior The code that passes the test suite (given above) provides different output than the traditional description of the problem. I think the test suite has an 'off by one' error in initializing the starting position. Current output with solution that passes test suite: Expected output per problem description: Relevant portion of problem description: See also discussion here: Proposed Fix Change test suite to Bug reported by jsdisco on the forum.
The issue seems to originate from the original challenge at the Rosetta Code, there's optional allowance for numbering prisoners from in solution, and that's what's happening in the used solution - Sample solution for the challenge also needs small change to use for initial label, instead of . And .
I'm confused in the example given in the description, if the executioner starts at 0 and kills every 2nd prisoner then shouldn't the first prisoner that is killed be "prisoner 2" and hence the killing order becomes . I think the challenge description is the one that has to be changed here. Also if numbering started from then the above killing order is just incremented by 1 which still won't be the solution given as example.
This is how I'm seeing it.
Killing every other would be 'safe', 'kill', 'safe' , 'kill', 'safe',.... But the current solution is 'safe', 'safe', 'kill', 'safe', 'kill', 'safe',... The solution/tests definitely have an off by one
I understood it wrongly . Also yea its the tests which are off by one. Looks like a good first issue.
Hi, I have a working solution for this, although not the most efficient one. It's relatively concise but using the time complexity is quadratic. Can I make a PR?
You can always open a PR. After that, we can give feedback and suggest changes if needed.
I'm not sure why you need to make a brand new solution. You just need to modify one of the existing solutions to reduce the starting value. In my solution, for example, you just set
Hi AFAIK, there is no compelling reason to completely change the original solution. The original solution has a better time complexity.

The only benefit to my approach is that the code is less error prone, since we are not implementing a fundamental data structure from scratch, and the basic steps of the algorithm that solve the problem are easier to read, since they are not mixed with the implementation details of the underlying data structure. I have already made a PR, but can fall back to the original solution, if you see necessary.
I agree that the original solution is pretty convoluted.