JSFiddle - React, Tailwind, and code Playground
by sonylnagale
JavaScript
function queueCreator(waitList){
let positionInQueue = 1
for (let i = 0; i < waitList.length; i++) {
waitList[i].id = function() {
return positionInQueue;
}
positionInQueue++;
}
return waitList;
}
const people = [{name: 'George'}, {name: 'Chris'}];
const queueList = queueCreator(people);
console.log(queueList[0].id());