Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda