[javascript] FE Dev screening

Viewer

copydownloadembedprintName: FE Dev screening
  1. const applyFilter = (_data, filters) => {
  2.     const filteredData = _data.filter(item => {
  3.         let dataPaired = []
  4.         filters.forEach(filter => {
  5.             if (filter.type === 'search') {
  6.                 const searchColumn = filter.searchColumn.split(',')
  7.                 dataPaired = [...dataPaired, searchColumn.some(key => {
  8.                     const searchTerm = filter.value.trim().toLowerCase()
  9.                     const columnData = item[key]
  10.                     if (Array.isArray(columnData)) {
  11.                         // If the column data is an array, we need to check if any of the items in the array contains the search term
  12.                         
  13.                     } else {
  14.                         return String(columnData).toLowerCase().includes(searchTerm)
  15.                     }
  16.                 })]
  17.             }
  18.         })
  19.         return !dataPaired.includes(false)
  20.     }) 
  21.     setData(filteredData)
  22. }

Editor

You can edit this paste and save as new:


File Description
  • FE Dev screening
  • Paste Code
  • 23 Mar-2023
  • 952 Bytes
You can Share it: