DEV Community

Discussion on: Daily Challenge #17 - Double Trouble

Collapse
 
kvharish profile image
K.V.Harish • Edited

Not a better solution compared to @alvaromontoro but here is mine in js


const doubleTrouble = (queue, nthCola) => {
  let person;
  for(let index = 0; index < nthCola; index++) {
    if(index+1 === nthCola) {
      person = queue[0];
      break;
    }
    queue = queue.flat(queue.push(Array(2).fill(queue.shift())));
  }
  return person;
};