How to filter array of strings from object , with dot between search terms?

Viewed 24

please consider this array of two objects where I have value_date with date values [yyyy, m, dd]. I want to create a functionality to allow user to enter date for example (26.07.2022.) and result should be an object with type Strategy Low risk 1.

[
    {
        "value_date": [
            2022,
            7,
            26
        ],
        "type": "Strategy Low risk 1",
        "net_amount": 52000.01,
        "balance": 52000.01,
        "quantity": 490.844,
        "price": 105.94,
        "debit": 0,
        "credit": 52000.01,
        "booking_date": [
            2022,
            7,
            26
        ],
        "file_id": 41989,
    },
    {
        "value_date": [
            2022,
            8,
            4
        ],
        "type": "Strategy Low risk 2",
        "net_amount": -48000.35,
        "balance": 3999.66,
        "quantity": 453.09,
        "price": 105.94,
        "debit": 48000.35,
        "credit": 0,
        "booking_date": [
            2022,
            8,
            4
        ],
        "file_id": 42334,
    }
]

This code works but partially by which I mean that when the user enters 26 or 7 or 2022, correct value will be returned, but how to extend this functionality to allow user to enter date like 26.7 or 26.7.2022 to get the appropriate result ? For now , when the user enter 22. , does not get any result.

const filterRows = (
  key: string,
  rows: Array<TableRowData>,
  callback: (arg: Array<TableRowData>) => void,
) => {
  {
    console.log('rows', rows)
  }
  const filteredRowData = rows.filter((row: TableRowData) => {
    {
      console.log('row', row)
    }
    const foundRow = Object.values(row).find((objValue) => {
      console.log('found', objValue)
      return objValue && objValue?.toString().includes(key)
    })
    return foundRow !== undefined
  })

  callback && callback(filteredRowData)
}
0 Answers
Related