Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. fuzzyContains = (text, search) => {
  2. debugger
  3. if (!text)
  4. return false
  5. if (!search)
  6. return true
  7.  
  8. search = search.toLowerCase()
  9. text = text.toString().toLowerCase()
  10.  
  11. let previousLetterPosition = -1
  12.  
  13. return search.split('').every(s => {
  14. debugger
  15. previousLetterPosition = text.indexOf(s, previousLetterPosition + 1)
  16.  
  17. return previousLetterPosition !== -1
  18. })
  19. }
  20.  
  21. handleSearch = search => {
  22. const {data} = this.state
  23. debugger
  24. let filteredData = data.filter(x => Object.keys(x).some(key => {
  25. debugger
  26. this.fuzzyContains(x[`<mark>${key}<mark/>`], search)}))
  27.  
  28. this.setState({filteredData, search})
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement