Advertisement
vaakata

13. Match the Dates

Oct 4th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function matchDates(input){
  2.     let dateMatchPattern = /\b\d{1,2}-\w{3}-\d{4}\b/g;
  3.  
  4.     for (let element of input) {
  5.         if (dateMatchPattern.test(input)) {
  6.             let date = element.match(dateMatchPattern).toString();
  7.             let day = date.split(/[-]+/)[0].trim();
  8.             let month = date.split(/[-]+/)[1];
  9.             let year = date.split(/[-]+/)[2];
  10.  
  11.             console.log(`${date} (Day: ${day}, Month: ${month}, Year: ${year})`);
  12.         }
  13.     }
  14. }
  15. matchDates(['I am born on 30-Dec-1994.'])
  16. matchDates(['This is not date: 512-Jan-1996.'])
  17. matchDates(['My father is born on the 29-Jul-1955.'])
  18. matchDates(['1-Jan-1999 is a valid date.']);
  19. matchDates(['So is 01-July-2000.']);
  20. matchDates(['I am an awful liar, by the way -- Ivo, 28-Sep-2016.']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement