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

166
Views
Why are the values of these two numbers not equal?

Having some trouble understanding why my numbers aren't giving me the correct equality in javascript.

I inserted a vector of numbers into an array in javascript...

const seen = [ 
                [0,1] 
              ];
console.log(contains(seen, [0,1]));

And then tried to do a simple comparison

    const contains = function(arr, coordinate){
        arr.forEach(element => {
            if(element[0] == coordinate[0] && element[1] == coordinate[1]){
         

       return true;
        }
    })

    return false;
}

Im expecting my contains function to return true. Element is [0,1] and the coordinate im comparing to is also [0,1], yet when I try to compare with the following:

element[0] == coordinate[0] && element[1] == coordinate[1]

It ultimately returns false.

Full code:

const contains = function(arr, coordinate) {
  arr.forEach(element => {
    if (element[0] === coordinate[0] && element[1] === coordinate[1]) {
      return true;
    }
  })

  return false;
}

const seen = [
  [0, 1]
];
console.log(contains(seen, [0, 1]))

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to change the forEach to a normal for. Right now return is returning only from the lambda.

const contains = function(arr, coordinate) {
    for (const element of arr) {
        if(element[0] == coordinate[0] && element[1] == coordinate[1]) {
            return true;
        }
    }
    return false;
}
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!