I'm working with a large array containing names of people, such as:
let names = [
"John Brown",
"Tristan Black",
"Carl Jobbs",
"Aidan Burrows",
"Taylor Joe"
];
When given an input, I want to return the top 5 most relevant results from this array. Currently, I am using a loop to check for names like this:
if(name.toLowerCase().includes(input.toLowerCase()))
{
console.log("Found match : " + name);
}
However, this method is not effective in finding the most relevant search results as it matches any name with the input in it.
My ideal solution would be to iterate through the array of names and identify the top 5 results that are most similar to the input. How can I achieve this?