Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

array swap method javascript

var a = [1,2,3,4,5], b=a.length;

for (var i=0; i<b; i++) {
    a.unshift(a.splice(1+i,1).shift());
}
a.shift();
//a = [5,4,3,2,1];
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #array #swap #method #javascript
ADD COMMENT
Topic
Name
3+1 =