Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
How to do spelling check with each of the property of an array of Object?

I am developing a program where a user will pass an argument and the program will give almost the same match of the result that it will find in an array of Object. So I have an array of object which is coming from a database so when my user will pass a name the search criteria on the array of object should work something like this suppose the user have passed a name called Jack Ma now on my array there are following objects like

[
{
name: "Jacky Ma"
},
{
name: "Jacky Man"
},
{
name: "Jack Mun"
},
{
name: "Jacob Ma"
},
{
name: "Jack Ma"
}
]

so for this following case Jacky Ma, Jack Mun, Jacob Ma should get retuned in an array of object. Only thing the program should check is the spelling of the each words matches with spelling of the words that are in the object lowerCase upperCase do not matter here for both words or if there is one or more than 2. The only thing it should check is the spelling of the words if the first word spelling matches with the spelling of the first word or 2nd word spelling matches with 2nd word of the object only then it should return. If neither or one do not get matched it should return empty array.

can anyone help me how can I do this ? Thanks in Advance.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In your current code, you are comparing the whole String "Jack Ma" and not "Jack" and "Ma". You need to split the name property and the string, loop over them and compare:

const filterData = searchClan.items.filter(
    n => {
        const splittedName = n.name.toLowerCase().split(' ');
        const splittedArgs = validateArgs.toLowerCase().split(' ');
        return splittedArgs.some((argument, index) => splittedName[index] && splittedName[index] === argument)
    });

The "some" method returns true if one of the element (at index "index" ) in the splittedArgs array matches with the element at index "index" in the splittedName array.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda