A file I'm working with that was made long before I started working here has a list of 53 different numeric values. But it has them all listed as a string separated by commas as such for example:
var numbers = "1,2,3,4,5,...,48,49,50";
Later in the script, when there is a check to see if a variable that's passed in exists, it uses:
if(numbers.indexOf(String(x),0) < 0) {/*do stuff*/} else {/*do other stuff*/}
While this works, I can't help but wonder why this way of doing it was chosen as opposed to making it an array of numbers. Would that be more optimal in terms of run-time then doing it the way it is currently set up?
Aucun commentaire:
Enregistrer un commentaire