The second is easier to maintain in my opinion since you could edit setting values to change behavior.
The first option is harder to read, consider the following:
function sortData(data,index){
data.sort(function(a,b){
if(a[index]>b[index]){return 1;}
if(a[index]<b[index]){return -1;}
return 0;
});
}
sortData(data,0);// sorts on open
where the second option might be easier to read:
function sortData(data,index){
data.sort(function(a,b){
if(a[index]>b[index]){return 1;}
if(a[index]<b[index]){return -1;}
return 0;
});
}
sortData(data,"open");// sorts on open
Especially if you want to sort on multiple columns. Getting values is obviously easier to read: data[0][0] or data[0]["open"] or data[0].open
Formatting output cold easily be done with:
function dailyData(open, high, low, close,volume,date){
//checking if data is valid comes here, maybe setting the
// right type for the values (like date as date instead of string)
this.open = open;
this.high = high;
this.low = low;
this.close = close;
this.volume=volume;
this.date=date;
this._dateYear={
rerurn this.date.getFullYear();
}
this.dateYear=this._dateYear();
}
To (not) answer your question: I'm not sure if you would get performance loss using option 2 but I've used large arrays of objects and even on older browsers didn't have a problem with it.