Javascript Array swap(index_A, index_B)

Description

Javascript Array swap(index_A, index_B)


// this approach is pretty bad but I wanted the end-result code
// to be more readable
// I'll probably switch this back later to better match js best practices

Array.prototype.swap = function(index_A, index_B) {
    var input = this;

    var temp = input[index_A];
    input[index_A] = input[index_B];//  w ww .ja v  a 2  s  .  co  m
    input[index_B] = temp;
}



PreviousNext

Related