function intercambiar(array, i, j) { var lon = array.length; //si los parametros son validos realiza el cambio if (i > -1 && i < lon && j > -1 && j < lon) { var auxiliar = array[i]; array[i] = array[j]; array[j] = auxiliar; } else { console.log("Indice fuera de rango"); } return array; } var vector = [9, 5, 7, 8, 1, 3]; console.log(intercambiar(vector, 0, 5)); * /