function CountingMinutes(str) { let arr = str.split("-"); // console.log(arr[0]); // code goes here let day = 24 * 60; let end = getMinutes(arr[1]); let start = getMinutes(arr[0]); // console.log('end is ' + end); // console.log('start is ' + start); if (end < start){ end += day; } return (end-start) ; } function getMinutes(time){ let hr = parseInt(time.split(':')[0]); let min = parseInt(time.split(':')[1].match(/[0-9]/g).join("")); let morning = time.match(/am/g); let pm = time.match(/pm/g); // console.log(pm); if (pm && hr < 12){ hr += 12; } else if (morning && hr === 12){ // convert midnight to zero hr += 12; } let totalMin = parseInt((hr*60) + min); return totalMin ; }