I have this array:
["2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-21", "2017-06-22", "2017-06-22", "2017-06-22", "2017-06-23", "2017-06-23", "2017-06-23", "2017-06-23", "2017-06-23", "2017-06-23", "2017-06-23", "2017-06-23", "2017-06-23", "2017-06-23", "2017-06-23", "2017-06-23", "2017-06-23", "2017-06-23", "2017-06-23", "2017-06-25", "2017-06-26", "2017-06-26", "2017-06-26", "2017-06-26", "2017-06-26", "2017-06-26", "2017-06-26", "2017-06-26", "2017-06-26", "2017-06-26", "2017-06-27"]
I'm trying to write a code to get this in output:
['date', "2017-06-2", "2017-06-22", "2017-06-23", "2017-06-24", "2017-06-25"]
['repeated_count', 5, 9, 3, 8, 4]
This is what I did but it's wrong:
var ChartDate = the above data ↑
var ChartDates = [];
var RepeatedNum = [];
for (i =0; i <= ChartDate.length; i++) {
if (ChartDates.indexOf(ChartDate[i]) < 0) {
if (typeof ChartDate[i] !== 'undefined') {
ChartDates.push(ChartDate[i]);
RepeatedNum.push('T');
}
}else {
RepeatedNum.push(1);
}
}
console.log(ChartDates);
console.log(RepeatedNum);
How can I solve this issue. Thanks for your help