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

170
Visualizações
Function within function I think?

Could someone please explain the syntax of this code. I dont need an explanation of 'some' function just the

(arrayValue => value === arrayValue);

within this function

function checkAvailability(array, value) {
  return array.some(arrayValue => value === arrayValue);
}
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

arrayValue refers to the abstract name of the item which is currently passing into your loop. You are checking if the function parameter value is equal to it. The final goal is here to check if there is at least one arrayValue that equals to value. The function will return a boolean.

For exemple:

const arr = ["joe", "jack"]    

function checkAvailability(array, value) { 
  return array.some(arrayValue => value === arrayValue);
 }

//  is there at least one item "joe" in the array. True.
console.log(checkAvailability(arr, "joe"))

//  is there at least one item "lola" in the array. False.
console.log(checkAvailability(arr, "lola"))

about 4 years ago · Juan Pablo Isaza Relatório

0

That's just a condition that checks if the given value is in the array.

Meaning, this logic takes each value of the array and checks the condition "value === arrayValue". where value is the given value and arrayValue is an element of the array.

And by definition of array.some, if this condition is true for at least one element of the array.

Then "array.some(arrayValue => value === arrayValue)" returns true else return false

about 4 years ago · Juan Pablo Isaza Relatório

0

That part of the function is an arrow function as It has only on single line you don't need to have curly brace and return key.

The code is equal to this one

function checkAvailability(array, value) {
    return array.some(function(arrayValue) {
        return value === arrayValue;
    })
}

As there is only one line in the body of callback function you can directly return it within a arrow function like this

array.some(arrayValue => value ===arrayValue)

And that part is the function which is use to check if the array have already some item which match the filter condition difine in the callback in this case value === arrayValue

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