/    Sign up×
Community /Pin to ProfileBookmark

swap method in Javascript

is there possible to do swap method in Javascript, if it is possible, how can i find some example. thank you

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangMay 24.2004 — ? swap what?
Copy linkTweet thisAlerts:
@VladdyMay 24.2004 — <i>
</i>Array.prototype.swap = function(index1,index2)
{ var temp = this[index1];
this[index1] = this[index2];
this[index2] = temp;
return;
}

Array.prototype.shuffle = function()
{ for(var i=0; i&lt;this.length; i++)
{ ind1 = Math.floor(Math.random()*this.length);
ind2 = Math.floor(Math.random()*this.length);
this.swap(ind1,ind2);
}
return;
}
Copy linkTweet thisAlerts:
@handong888authorMay 24.2004 — what is the Array.prototype.swap mean? thank you
×

Success!

Help @handong888 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...