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

174
Views
expected a identifier instead saw '('. expected a identifier instead saw ')'

I am using bubble sort to sort a array but when I write swap function , I'm getting error when writing the line function swap(arr,j,j+1) I am getting the err" expected ')' to match from '('

function solve(N, arr){
 for (var i = 0; i < N; i++){
   for(var j = 0; j < (N - i - 1); j++){
     if (arr[j] > arr[j + 1]) {
      swap(arr, j, j + 1)
     }
   }
 }
 

function swap(arr,j,j+1) //getting error here "expected a identifier instead saw '('.  expected a identifier instead saw ')'. "[look at the screenshot ][1]
{
     var temp = arr[j];
       arr[j] = arr[j + 1];
       arr[j + 1] = temp;
}
  
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The problem is that you have an expression j+1 as a parameter in your function.

function swap(arr, j, j + 1)

You cannot do that, you either rename j + 1 to k for example. But why even send them both in the first place if k = j + 1? You could accomplish this by only using

function swap(arr,j)
{
     var temp = arr[j];
       arr[j] = arr[j + 1];
       arr[j + 1] = temp;
}

and calling the function just as

swap(arr,j);
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!