I have object, keys are dates, before dot are months, after are years:
const dataObj = {
'01.2015': 0.01,
'02.2015': 0.10,
'03.2015': 0.05,
'04.2015': 0.25,
// ...
}
the function takes two dates and return an array with objects containing values from the dataObj
interface Point {
date: string;
value: number;
}
type Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
type Day = `${Digit}${Digit}`;
type Month =
| '01'
| '02'
// ...
| '11'
| '12';
type Year = '2015' | '2016' | '2017';
type DateString = `${Day}.${Month}.${Year}`;
type MonthDateString = `${Month}.${Year}`;
function count(firstDate: DateString, secondDate: DateString): Point[] {
const result: Point[] = [];
let currentDate = firstDate.slice(3) as MonthDateString;
// loop through dataObj and push in result
return result // [{date: '01.2015', value: 0.01}, {...}, ...]
}
How to loop through dataObj? I tried for loop
for(let i = currentDate; i !== secondDate.slice(3); )
but have no idea what to do with final-expression, how to update counter variable, pass next key(string with date) from dataObj.