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

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

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 Denunciar

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 Denunciar

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