sample test

mail@pastecode.io avatar
unknown
javascript
3 years ago
759 B
1
Indexable
Never

var values=['0102-0306','0412+0908','0903']; 

values.forEach(input=>{
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
let word="",splitter="";
if(input.includes("-")) {splitter='-'; word="and"; }
else if(input.includes("+")) {splitter='+'; word="to";}
 let start='',end='',s='',e='',endMonth='',startMonth='';
if(splitter==="") {
 console.log(input.substring(0,2)+" "+months[Number(input.substring(2))-1]);
  console.log('\n');
}
else {
[start,end]=input.split(splitter);
startMonth=months[Number(start.substring(2))-1];
endMonth=months[Number(end.substring(2))-1];
s =`01 ${startMonth}`; 
e = `02 ${endMonth}`;
console.log(s+` ${word} `+e);
console.log('\n');
}
  
})