var list = [1,2,3,4,5,6,7,8,9];
var i=0;
var n=3;
var tmp=[];
var len = list.length
while(tmp.length!=(len-1)){
if(((i+1)%3) != 0){
list.push(list[i]);
}else{
tmp.push(list[i]);
}
console.log(tmp.length)
i++;
}
console.log(list[i])
console.log(tmp)
console.log(list)
function g(n,x){
var list = [];
for(i=1;i<=n;i++){
list.push(i);
}
var i=0;
var tmp=[];
var len = list.length
while(tmp.length!=(len-1)){
if(((i+1)%x) != 0){
list.push(list[i]);
}else{
tmp.push(list[i]);
}
//console.log(tmp.length)
i++;
}
//console.log(list[i])
return list[i]
}