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

299
Visualizações
Put array like [1,3] give the error 'Uncaught SyntaxError: Invalid destructuring assignment target'

I write a bubble sort function to arrange numbers in the array, but when I put array like [1,3] ,vscode and chrome give me the

Identifier expected.javascript OR Uncaught SyntaxError: Invalid destructuring assignment target

here is the full code

function bubbleg(arr) {

  var len = arr.length;
  for (var i = 0; i < len - 1; i++) {
    for (var j = 0; j < len - 1 - i; j++) {
      if (arr[j] > arr[j + 1]) {
        var temp = arr[j];
        arr[j] = arr[j + 1];
        arr[j + 1] = temp;

      }
    }
  }
  return arr;
}

function bubbleg([1, 3]);

After make a change, like

num= [1,3] function bubbleg(num);

Everything is good, but why we can not put the something like bubbleg([1,3])? Is there any books so when I look it up with some bugs list in it ?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

remove function keyword in calling your function. function is keyword used to declare function, not to call it.

function bubbleg(arr) {
  var len = arr.length;
  for (var i = 0; i < len - 1; i++) {
    for (var j = 0; j < len - 1 - i; j++) {
      if (arr[j] > arr[j + 1]) {
        var temp = arr[j];
        arr[j] = arr[j + 1];
        arr[j + 1] = temp;

      }
    }
  }
  return arr;
}
bubbleg([1, 3]);
about 4 years ago · Juan Pablo Isaza Relatório

0

that is because you're not calling the function bubbleg correctly

function bubbleg([1,2])

should be

bubbleg([1,2])
about 4 years ago · Juan Pablo Isaza Relatório

0

It is not about the [1, 3] argument you pass. But how you call the function.

Here is the correct code:

function bubbleg(arr) {

    var len = arr.length;
    for (var i = 0; i < len - 1; i++) {
        for (var j = 0; j < len - i - 1; j++) {
            if (arr[j] > arr[j + 1]) {
                var temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;

            }
        }
    }
    return arr;
} 
        
 console.log(bubbleg( [3,1] ));

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