0
Write a java script program to swap the 3 number without function
3 Réponses
+ 3
Mike Utty you are right, but only in ES6
Use array destructuring in ES6
https://code.sololearn.com/WTvgbMwzi2Gg/?ref=app
+ 2
uh been awhile. I think
[a,b,c] = [c,b,a] works also. I may be wrong.
0
I think "swap" is defined for two elements only. One can't swap simultaneously among three elements just like you can't add three numbers simultaneously. You'll have to add two of them and then third to their result.
So, swap the two numbers and then exchange third with any of the exchanged two.
a= a+b
b= a-b
a= a-b
similarly among c & a or c & b.