Numbered from 1 to 100 of the one hundred people in a circle, to count off in 123123, count to 3, the circle of people automatically quit the rest continue to count off, asking the last remaining Numbers for?
Var stackArr=[];
For (var j=1; j<=100; J++) {
StackArr. Push (j);
}
The function josephusStackDeal (obj) {
Var objArr=obj. ObjArr | | [];
If (objArr. Length==0) {
return;
}
Var newArr=obj. NewArr | | [];
Var newObj={};
Var firstEle=' ';
Var secondEle=' ';
Var thirdEle=' ';
If (objArr. Length==1) {
NewArr. Push (objArr [0] 1);
ObjArr=[];
NewObj={
ObjArr: objArr,
NewArr: newArr
}
The console. The log (newObj. NewArr)
Return newObj;
}
If (objArr. Length==2) {
ThirdEle=objArr. Shift ();
NewArr. Push (thirdEle - 1);
NewObj={
ObjArr: objArr,
NewArr: newArr
}
JosephusStackDeal (newObj);
//return
}
If (objArr. Length> 2) {
FirstEle=objArr. Shift ();
SecondEle=objArr. Shift ();
ThirdEle=objArr. Shift ();
ObjArr. Push (firstEle);
ObjArr. Push (secondEle);
NewArr. Push (thirdEle - 1);
NewObj={
ObjArr: objArr,
NewArr: newArr
}
JosephusStackDeal (newObj);
//return;
}
}
JosephusStackDeal ({objArr: stackArr newArr: []})