Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda