Skip to content

Instantly share code, notes, and snippets.

@mjarpitanand
Last active November 22, 2017 05:54
Show Gist options
  • Save mjarpitanand/791f469e8b06e2db6c258f99c170f801 to your computer and use it in GitHub Desktop.
Save mjarpitanand/791f469e8b06e2db6c258f99c170f801 to your computer and use it in GitHub Desktop.
function Queue(){
var items = [];
this.enque = function(ele){
items.push(ele);
}
this.deque = function(){
return items.shift();
}
this.print = function(){
alert(items);
}
this.size = function(){
return items.length;
}
}
function game(namelist , num){
let q = new Queue();
for(i = 0 ;i< namelist.length;i++){
q.enque(namelist[i]);
}
let eliminated = "";
while(parseInt(q.size()) > 1){
for(var i =0 ; i< num;i++){
q.enque(q.deque());
}
eliminated = q.deque();
console.log('Eliminated people is: ' + eliminated);
}
return q.deque();
}
let names = ['Arpit' , 'Anand' , 'Raj' ,'nameone' , 'nametwo'];
console.log('Winner is:'+game(names , 10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment