i got a quick one for someone who can help. I've downloaded some data from yahoo. I want to split the data into a N x 7 array. (is that the correct term?). I want it to look like this:
[[2013年01月29日,64.25,65.03,64.00,64.24,4883100,64.24],[2013年01月28日,64.51,64.87,63.27,64.59,7591300,64.59],...]
but now, as you can see, it's not in that format. Novice to javascript. Please help.
function function() {
var ticker='YUM';
var startMonth=0; var startDate=1; var startYear=2013;
var endMonth=0; var endDate=25; var endYear=2013;
var fetchString="http://ichart.finance.yahoo.com/table.csv?s="+ticker+"&a="+startMonth+"&b="+startDate+"&c="+startYear+"&d="+endMonth+"e="+endDate+"&f="+endYear+"&g=d";
var response = UrlFetchApp.fetch(fetchString);
a=response.getContentText();
var allData = a.slice(a.indexOf("2013"));
}
1 Answer 1
Assuming you don't want the column headers, this is a one line change:
var allData = a.match(/(.*?)\n/g) // convert each line to a row
.splice(1) // remove headers row
.map(function(row){
return row.replace(/\n/,'').split(',');
}); // convert row string to array
answered Jan 30, 2013 at 17:46
JSDBroughton
4,0644 gold badges35 silver badges55 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
jason
Thanks Jonathon! Worked very well! There are so many websites out there, what is the best place to go to get a reference book on the methods you have used in your code? Thanks again for the response. Regards.
JSDBroughton
This is less helpful an answer, but I don't think I've ever read a js book.
lang-js