FriendlyDate Ranges : Octal litteral or escape deprecated . Help

FriendlyDate Ranges : Octal litteral or escape deprecated . Help
0

#1

I need help about this error message. My issue is with the FriendlyDate Renges challenge. My approach is to check each date to match the correct pattern (regex) then proceed the display (return) depending on each configurations. May not the efficient way. But what i am concernet it the error message Octal litterals or octal escapes are deprecated.

I don’t think it is the regular expression as I worked on different challenges already here (even if i have to improve my regex skills)

The parseInt works well as it takes string not numverical value in octal , hex or binary base

So here is my code :

function reformateDates(arr) {
// YYYY-MM-DD
// It check the date format and return simply in array of [year, month, date]—

var dateFormat =/([0-9]{4})(-)([0]?([1-9])|1)(-)([0-2]?([1-9])(?!.)|3(?!.))/g;
console.log(arr.match(dateFormat));
if (arr.match(dateFormat)!==null){
arr = arr.split(’-’);
}

switch(parseInt(arr[1])){
case 1:
arr[1] = “January”;
break ;
case 2:
arr[1] = “Febuary”;
break;
case 3:
arr[1] = “March”;
break;
case 4:
arr[1] = “April”;
break;
case 5:
arr[1] = “May”;
break ;
case 6:
arr[1] = “June”;
break;
case 7:
arr[1] = “July”;
break;
case 08:
arr[1] = “August”;
break;
case 9:
arr[1] = “September”;
break ;
case 10:
arr[1] = “October”;
break;
case 11:
arr[1] = “November”;
break;
case 12:
arr[1] = “December”;
break;

}

switch(parseInt(arr[2])){
case 1:
arr[2] =‘1st’;
break;
case 21:
arr[2] =‘21st’;
break;
case 31:
arr[2] =‘31st’;
break;
case 2:
arr[2] =‘2nd’;
break;
case 22:
arr[2] =‘22st’;
break;
case 3:
arr[2] =‘3rd’;
break;
case 23:
arr[2] =‘23rd’;
break;
default:
arr[2]+=‘th’;

}

return arr;
}

reformateDates(‘2016-08-31’);
function makeFriendlyDates(arr) {
arr[0]= reformateDates(arr[0]);
arr[1]= reformateDates(arr[1]);
var result =[];
if(arr[0][0]===arr[1][0] && arr[0][1]===arr[1][1] ){
return [arr[0].slice(1).join(" "),arr[0][1]] ;
}else if(arr[0][0]===arr[1][0]){
return [arr[0].slice(1).join(’ ‘).concat(’, ‘,arr[0][0]), arr[1].slice(1).join(’ ')];
}

}
Note: not finished but there is already two cases that should work at least on FCC.

Thank for your help and explanation.


#2

Remove zero before 8.

case 08:
arr[1] = "August";

Also you have a typo in 22nd :wink:


#3

Hello Jenovs many thanks. Really frustrating :cry: as 95% of time when i get stuck like this, it is always a simply error that i don’t see in the code and looking for something complicated.