Created
April 30, 2015 02:27
-
-
Save stevez/e0d3906c19ed94e13fdc to your computer and use it in GitHub Desktop.
scala array swap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val s = Array(1,2,3,4,5) | |
| for( i<-1 until (s.length, 2)) { | |
| val t = s(i-1) | |
| s(i-1) = s(i) | |
| s(i) = t | |
| } | |
| s | |
| //Array[Int] = Array(2, 1, 4, 3, 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment