I have a question which is more about best practices than actually solving code problems. I know the code works and I've seen somewhat similar questions for other languages but I'd like to get a resolution on this.
var parkRides = [["Birch Bumpers", 40] , ["Pines Plunge", 55] , ["cedar Coaster", 20] , ["Ferris Whell of Firs", 90]];
var fastPassQueue = ["Cedar Coaster","Pines Plunge","Birch Bumpers","Pines Plunge"];
var wantsRide = "Cedar Coaster";
function buildTicket (allRides, passRides, pick ) {
if(passRides[0] == pick){
var pass = passRides.shift();
return function() {alert("Quick! You've got a Fast Pass to " + pass + "!");
};
} else {
for(var i = 0; i<allRides.length; i++){
if(allRides[i][0] == pick){
return function (){alert("A ticket is printing for " + pick + "!\n" + "Your wait time is about " + allRides[i][1] + " minutes.");
};
}
}
}
}
In the above example the function "buildTicket" takes in 3 parameters;
- allRides which takes the value of the variable parkRides
- passRides which takes the value of the variable fastPassQueue
- pick which takes the value of the variable wantsRide
Through altering the function code I know that
var ticket = buildTicket(parkRides, fastPassQueue, wantsRide);
delivers the exact same results as
var ticket = buildticket(allRides, passRides,pick);
My question is whether one method is preferred over the other? Is it acceptable to code a function to directly use the variable names or is it better to give the parameters different names within the function.
Thanks.