fix gaps in sale data

by frogggeee McFrogggeee

HTML

5/31/2017	3097.77
6/1/2017	4165.01
6/2/2017	4722.91
6/3/2017	4938.08
6/4/2017	4388.58
6/5/2017	3912.3
6/6/2017	4052.33
6/7/2017	3924.6
6/8/2017	3622.3

CSS

5/31/2017	3097.77
6/1/2017	4165.01
6/2/2017	4722.91
6/3/2017	4938.08
6/4/2017	4388.58
6/5/2017	3912.3
6/6/2017	4052.33
6/7/2017	3924.6
6/8/2017	3622.3
6/9/2017	4268.14
6/10/2017	3998.21
6/11/2017	3784.95
6/12/2017	2995.8
6/13/2017	3579.13
6/14/2017	3983.42
6/15/2017	3477.65
6/16/2017	4035.77
6/17/2017	4379.06
6/18/2017	3427.95
6/19/2017	4116.34
6/20/2017	4050.92
6/21/2017	4558.66
6/22/2017	4336.68
6/23/2017	4941.98
6/24/2017	5009.78
6/25/2017	4578.31
6/26/2017	3647.7
6/27/2017	3772.33
6/28/2017	3970.78
6/29/2017	3980.8
6/30/2017	4751.69
7/1/2017	4075.34
7/2/2017	3413.49
7/3/2017	3895.23
7/4/2017	2746.39
7/5/2017	3369.41
7/6/2017	3748.61
7/7/2017	3895.81
7/8/2017	4140.98
7/9/2017	3503.07
7/10/2017	3330.74
7/11/2017	3166.35
7/12/2017	3225.9
7/13/2017	3749.43
7/14/2017	4448.31
7/15/2017	4176.69
7/16/2017	3813.91
7/17/2017	3261.14
7/18/2017	3466.81
7/19/2017	3634.91
7/20/2017	3388.96
7/21/2017	3585.16
7/22/2017	4093.84
7/23/2017	3256.76
7/24/2017	3273.29
7/25/2017	3867.74
7/26/2017	3693.66
7/27/2017	3466.49
7/28/2017	3826.48
7/29/2017	3912.83
7/30/2017	3786.55
7/31/2017	3378.83
8/1/2017	3969.71
8/2/2017	4733.52
8/3/2017	4145.29
8/4/2017	3683.84
8/5/2017	3590.29
8/6/2017	3042.79
8/7/2017	3021.59
8/8/2017	3069.87
8/9/2017	3285.1
8/10/2017	3734.85
8/11/2017	3192.13
8/12/2017	3498.72
8/13/2017	3087.39
8/14/2017	2843.71
8/15/2017	3220.51
8/16/2017	3508.45
8/17/2017	3290.85
8/18/2017	3890.8
8/19/2017	4192.34
8/20/2017	3652.12
8/21/2017	2937.83
8/22/2017	3587.17
8/23/2017	3161.15
8/24/2017	3486.29
8/25/2017	3963.51
8/26/2017	3680.13
8/27/2017	3416.13
8/28/2017	3337.14
8/29/2017	3382.79
8/30/2017	3072.75
8/31/2017	3114.88
9/1/2017	3450.21
9/2/2017	2958.72
9/3/2017	2780.19
9/4/2017	3201.68
9/5/2017	2989.66
9/6/2017	2479.8
9/7/2017	2916.36
9/8/2017	3585.63
9/9/2017	3717
9/10/2017	3160.04
9/11/2017	2977.88
9/12/2017	2728.83
9/13/2017	3363.65
9/14/2017	3382.7
9/15/2017	4047.16
9/16/2017	3620.46
9/17/2017	2174.13
9/18/2017	2335.65
9/19/2017	2585.4
9/20/2017	2979.17
9/21/2017	2770...

JavaScript

/*
Objective: 
Fix gaps in sales data.

Method:
The gaps in the sales data (skipped dates missing from the data set) will be 
filled in with "[date] + tab + undefined"

Loop through every line of data and if the date from the previous line doesnt equal the increment from the getDate() function, add the date. 

*/
let data = prompt();
// split by tab: \t
data = (data.split("\n"))
let newData = "";
// loop through each item in data, check if the getDate + [one day] from the previous item equals the getDate from the current item. if it doesn't, add lines of ([date] + tab + undefined) until the date from the current item is reached.

function difference(date1, date2) {
    // Define the reference date (day 0)
    var referenceDate = new Date(date1); // January 1, 1970

    // Calculate the difference in milliseconds between the given date and the reference date
    var differenceInMilliseconds = date2.getTime() - referenceDate.getTime();

    // Convert milliseconds to days
    var dayNumber = differenceInMilliseconds / (1000 * 3600 * 24);

    // Return the calculated day number
    return Math.round(dayNumber);
}
function futureDay(inputDate, days) {
    // Create a new Date object based on the input date
    var nextDay = new Date(inputDate);

    // Increment the date by one day
    nextDay.setDate(nextDay.getDate() + days);

    // Return the date that is one day later
    var year = nextDay.getFullYear();
    var month = ('0' + (nextDay.getMonth() + 1)).slice(-2); // Adding 1 because getMonth() returns zero-based month
    var day = ('0' + nextDay.getDate()).slice(-2);

    // Concatenate components into a string in the format "YYYY-MM-DD"
    var dateString = month + '/' + day + '/' + year;

    // Return the formatted date string
    return dateString;
}
for (let i = 0; i < data.length-1; i++) {
	let diff = difference(new Date(data[i].split("\t")[0]), new Date(data[i+1].split("\t")[0]));
  if (diff != 1) {
  for (let j = 0; j < diff; j++) {
  	newData +=...