main.js 422 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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)); * /