0

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"));
}
j0k
22.8k28 gold badges82 silver badges90 bronze badges
asked Jan 30, 2013 at 16:26

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

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.
This is less helpful an answer, but I don't think I've ever read a js book.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.