Created
January 13, 2015 22:23
-
-
Save winnab/88dd028685bf91914d20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var datesCop14 = [ | |
'12/31/13', | |
'01/02/14', | |
'01/03/14', | |
'01/06/14', | |
'01/07/14', | |
'01/08/14', | |
'01/09/14', | |
'01/10/14', | |
'01/13/14', | |
'01/14/14', | |
'01/15/14', | |
'01/16/14', | |
'01/17/14', | |
'01/20/14', | |
'01/21/14', | |
'01/22/14', | |
'01/23/14', | |
'01/24/14', | |
'01/27/14', | |
'01/28/14', | |
'01/29/14', | |
'01/30/14', | |
'01/31/14', | |
'02/03/14', | |
'02/04/14', | |
'02/05/14', | |
'02/06/14', | |
'02/07/14', | |
'02/10/14', | |
'02/11/14', | |
'02/12/14', | |
'02/13/14', | |
'02/14/14', | |
'02/17/14', | |
'02/18/14', | |
'02/19/14', | |
'02/20/14', | |
'02/21/14', | |
'02/24/14', | |
'02/25/14', | |
'02/26/14', | |
'02/27/14', | |
'02/28/14', | |
'03/03/14', | |
'03/04/14', | |
'03/05/14', | |
'03/06/14', | |
'03/07/14', | |
'03/10/14', | |
'03/11/14', | |
'03/12/14', | |
'03/13/14', | |
'03/14/14', | |
'03/17/14', | |
'03/20/14', | |
'03/21/14', | |
'03/24/14', | |
'03/25/14', | |
'03/26/14', | |
'03/27/14', | |
'03/28/14', | |
'03/31/14', | |
'04/01/14', | |
'04/02/14', | |
'04/03/14', | |
'04/04/14', | |
'04/07/14', | |
'04/08/14', | |
'04/09/14', | |
'04/10/14', | |
'04/11/14', | |
'04/14/14', | |
'04/17/14', | |
'04/22/14', | |
'04/23/14', | |
'04/24/14', | |
'04/25/14', | |
'04/28/14', | |
'04/29/14', | |
'04/30/14', | |
'05/01/14', | |
'05/02/14', | |
'05/06/14', | |
'05/07/14', | |
'05/08/14', | |
'05/09/14', | |
'05/12/14', | |
'05/13/14', | |
'05/14/14', | |
'05/15/14', | |
'05/16/14', | |
'05/19/14', | |
'05/22/14', | |
'05/23/14', | |
'05/27/14', | |
'05/28/14', | |
'05/29/14', | |
'05/30/14', | |
'06/02/14', | |
'06/03/14', | |
'06/04/14', | |
'06/05/14', | |
'06/06/14', | |
'06/09/14', | |
'06/10/14', | |
'06/11/14', | |
'06/12/14', | |
'06/13/14', | |
'06/16/14', | |
'06/19/14', | |
'06/20/14', | |
'06/23/14', | |
'06/24/14', | |
'06/25/14', | |
'06/26/14', | |
'06/27/14', | |
'06/30/14', | |
'07/01/14', | |
'07/02/14', | |
'07/03/14', | |
'07/04/14', | |
'07/07/14', | |
'07/08/14', | |
'07/09/14', | |
'07/10/14', | |
'07/11/14', | |
'07/14/14', | |
'07/17/14', | |
'07/18/14', | |
'07/21/14', | |
'07/22/14', | |
'07/23/14', | |
'07/24/14', | |
'07/25/14', | |
'07/28/14', | |
'07/29/14', | |
'07/30/14', | |
'07/31/14', | |
'08/01/14', | |
'08/04/14', | |
'08/05/14', | |
'08/06/14', | |
'08/07/14', | |
'08/08/14', | |
'08/11/14', | |
'08/12/14', | |
'08/13/14', | |
'08/14/14', | |
'08/15/14', | |
'08/18/14', | |
'08/21/14', | |
'08/22/14', | |
'08/26/14', | |
'08/27/14', | |
'08/28/14', | |
'08/29/14', | |
'09/01/14', | |
'09/02/14', | |
'09/03/14', | |
'09/04/14', | |
'09/05/14', | |
'09/08/14', | |
'09/09/14', | |
'09/10/14', | |
'09/11/14', | |
'09/12/14', | |
'09/15/14', | |
'09/18/14', | |
'09/19/14', | |
'09/22/14', | |
'09/23/14', | |
'09/24/14', | |
'09/25/14', | |
'09/26/14', | |
'09/29/14', | |
'09/30/14', | |
'10/01/14', | |
'10/02/14', | |
'10/03/14', | |
'10/06/14', | |
'10/07/14', | |
'10/08/14', | |
'10/09/14', | |
'10/10/14', | |
'10/13/14', | |
'10/16/14', | |
'10/17/14', | |
'10/20/14', | |
'10/21/14', | |
'10/22/14', | |
'10/23/14', | |
'10/24/14', | |
'10/27/14', | |
'10/28/14', | |
'10/29/14', | |
'10/30/14', | |
'10/31/14', | |
'11/03/14', | |
'11/04/14', | |
'11/05/14', | |
'11/06/14', | |
'11/07/14', | |
'11/10/14', | |
'11/11/14', | |
'11/12/14', | |
'11/13/14', | |
'11/14/14', | |
'11/17/14', | |
'11/20/14', | |
'11/21/14', | |
'11/24/14', | |
'11/25/14', | |
'11/26/14', | |
'11/27/14', | |
'11/28/14', | |
'12/01/14', | |
'12/02/14', | |
'12/03/14', | |
'12/04/14', | |
'12/05/14', | |
'12/08/14' | |
]; | |
var settles = [ | |
7372.75, | |
7403.5, | |
7327.5, | |
7343.5, | |
7361, | |
7354.5, | |
7235.25, | |
7327.75, | |
7365, | |
7365, | |
7365, | |
7324, | |
7363, | |
7339, | |
7371, | |
7320.5, | |
7227, | |
7207, | |
7185.5, | |
7178.5, | |
7159, | |
7139, | |
7103, | |
7081.5, | |
7087.5, | |
7088.5, | |
7181.5, | |
7194, | |
7140, | |
7111.5, | |
7201, | |
7143, | |
7181, | |
7204.5, | |
7204.5, | |
7204.5, | |
7187, | |
7195, | |
7114, | |
7106, | |
7076.5, | |
7068, | |
7059, | |
7005, | |
7087.5, | |
7064.5, | |
7070, | |
6808, | |
6664, | |
6492.5, | |
6527.75, | |
6434, | |
6488, | |
6500.5, | |
6443.5, | |
6492.5, | |
6480.5, | |
6610.5, | |
6515.75, | |
6574.5, | |
6686, | |
6652, | |
6667.5, | |
6679, | |
6646, | |
6622, | |
6672.5, | |
6672, | |
6623.5, | |
6657.75, | |
6664.25, | |
6661.75, | |
6661.5, | |
6684, | |
6686.5, | |
6774, | |
6785, | |
6767.5, | |
6734, | |
6662.5, | |
6672, | |
6753.5, | |
6756, | |
6688.5, | |
6772, | |
6797, | |
6924, | |
6888, | |
6975, | |
6938, | |
6922, | |
6983, | |
6924, | |
6981, | |
6988.5, | |
7013, | |
6946, | |
6892, | |
6974.5, | |
6902.5, | |
6809, | |
6789, | |
6691, | |
6684.5, | |
6696, | |
6725, | |
6634.5, | |
6673.5, | |
6718.5, | |
6733.5, | |
6836.5, | |
6901, | |
6903.5, | |
6929, | |
6973.5, | |
6966, | |
7036, | |
7038.5, | |
7139.5, | |
7189, | |
7164, | |
7128, | |
7136, | |
7141, | |
7177.5, | |
7173.5, | |
7121.5, | |
7067.5, | |
6987.5, | |
7029.25, | |
7038, | |
7040.75, | |
7172.5, | |
7130, | |
7125.25, | |
7090.5, | |
7141.25, | |
7123.5, | |
7078.5, | |
7130.5, | |
7059.5, | |
6977.25, | |
7009, | |
7004.75, | |
7004, | |
6975.75, | |
6892.5, | |
6834, | |
6887, | |
6943, | |
7027, | |
7086, | |
7062.5, | |
7041, | |
6947, | |
6996.5, | |
6961, | |
6983, | |
6924, | |
6949.5, | |
6993, | |
7003, | |
6859.5, | |
6892.75, | |
6859, | |
6864.5, | |
6867, | |
6864.75, | |
6862.25, | |
6756.5, | |
6752, | |
6770.5, | |
6728, | |
6755.5, | |
6777.5, | |
6710, | |
6722.75, | |
6643, | |
6679, | |
6746, | |
6706.75, | |
6685, | |
6774.5, | |
6699.5, | |
6784, | |
6587, | |
6675, | |
6595, | |
6703.75, | |
6674, | |
6738, | |
6744, | |
6782, | |
6855.5, | |
6876.5, | |
6797, | |
6752, | |
6770, | |
6703, | |
6706.5, | |
6730.5, | |
6785, | |
6725, | |
6755.5, | |
6747.5, | |
6724, | |
6777, | |
6776, | |
6711.75, | |
6772, | |
6720, | |
6644, | |
6619, | |
6609.5, | |
6409, | |
6517, | |
6471, | |
6433.5, | |
6530.5, | |
6508, | |
6456.25 | |
]; | |
window.onload = function() { | |
function getClosingDayDataForMonth(month, year) { | |
return year.reduce(function ( ret, day, i ) { | |
var currDate = new Date(day); | |
// make sure ret has a value for each property | |
// set a value if needed | |
if ( | |
ret.monthCloseDate === null || | |
ret.monthCloseIx === null | |
) { | |
ret.monthCloseDate = currDate; | |
ret.monthCloseVal = settles[i]; | |
ret.monthCloseIx = i; | |
return ret; | |
} | |
// check to see that the current month | |
// is the same as the month passed in | |
var monthToMatch = new Date(month).getMonth(); | |
var currMonth = currDate.getMonth(); | |
if ( currMonth !== monthToMatch ) { | |
return ret; | |
} | |
// if you're on the right month, | |
// check the currDate against ret's date | |
// and save over ret's props | |
// if the currDate is after ret's date | |
if ( ret.monthCloseDate < currDate ) { | |
ret.monthCloseDate = currDate; | |
ret.monthCloseVal = settles[i] | |
ret.monthCloseIx = i; | |
return ret; | |
} | |
}, { | |
monthCloseDate: null, | |
monthCloseVal: null, | |
monthCloseIx: null | |
}); | |
} | |
var monthClosings = []; | |
for ( var i = 0; i < 12; i++ ) { | |
var date = new Date(2014, i); | |
console.log(getClosingDayDataForMonth(date, datesCop14)); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment