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

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

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 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