Similar to this data format, how to cut into two arrays, divided into morning time, afternoon time, with 12: 00 as the dividing line

similar to this kind of data, how to cut into two arrays, divided into morning time and afternoon time, with 12: 00 as the dividing line
[{time: 8:30}, {time: 8:15}], [{time: 9: 00}, {time: 9: 10}, {time: 9: 15}], [{time: 10: 00}], [{time: 1:00}], [{time: 1:15}]

May.27,2021

instead of using date to calculate the time, it is better to use a regular expression to match the number of hours. If it is greater than 12, it is afternoon, and less than 12, it is morning

.
/\s*(\d{1,2})\s*:\s*\d{1,2}\*/

match the first grouping


const data = [[{time: '8:30'}, {time: '8:15'}],[{time: '9: 00'}, {time: '12: 10'}, {time: '9: 15'}],[{time: '10: 00'}],[{time: '14:00'}], [{time: '1:15'}]]


function trans (data) {
  data = [].concat.apply([], data) // 
  const before = []
  const after = []
  data.forEach(cur => {
    let hour = +cur.time.split(':')[0].trim()
    if (hour < 12) {
      before.push(Object.assign({}, cur))
    } else {
      after.push(Object.assign({}, cur))
    }
  })
  return {
    before,
    after
  }
}
trans(data)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3839c-2c0fe.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3839c-2c0fe.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?