// this.collectPairs() returns data from the UI form 
// this.alert.alarmReasons contains empty array or alarmReason-Category pair objects

let newAlarmReasonsToAdd = []

this.collectPairs().forEach(categoryAndAlarmReasonPair => {
  !!!this.searchAmidExisting(categoryAndAlarmReasonPair, this.alert.alarmReasons) ? newAlarmReasonsToAdd.push(categoryAndAlarmReasonPair) : null
})

searchAmidExisting(alarmReasonToAdd, existingAlarmReasons){
    let res = existingAlarmReasons.find(existing => {
    if(alarmReasonToAdd.categoryDictEntryKey === existing.category && alarmReasonToAdd.reasonDictEntryKey === existing.reason){
      return true
    } else return false
  })
    return res
  }
By mallioppilas, 2023-11-03 14:13:41