I have data with information about users:
users: [{ first_name: 'Вова', last_name: 'Нуйкин', domain: 'kebab' }, { first_name: 'Вова', last_name: 'Воробьев', domain: 'vorobey' }] My task is to do a search by users, but I do not know which search algorithm will be good, for searching by users, if I type in the search line "Vova" or "Vova Nu" or "Nuyk" or "kebab".
I wrote a function in which I check the first N letters in user.first_name , user.last_name and user.domain . The search works when I type "Vova", "Nuikin", or "kebab", but problems start when I look for "Vova Nuykin". In this case, searchResults Vova Nuikin and Vova Vorobyev are recorded in searchResults . How can I fix this?
This is my function:
search = (users, value) -> searchResults = [] for user in users for value in values if user.first_name.toLowerCase().slice(0, value.length).includes(value) or user.last_name.toLowerCase().slice(0, value.length).includes(value) or user.domain.toLowerCase().slice(0, value.length).includes(value) searchResults.push(user) return searchResults