Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!