Skip to content

Instantly share code, notes, and snippets.

@stevez
Created April 30, 2015 02:27
Show Gist options
  • Select an option

  • Save stevez/e0d3906c19ed94e13fdc to your computer and use it in GitHub Desktop.

Select an option

Save stevez/e0d3906c19ed94e13fdc to your computer and use it in GitHub Desktop.
scala array swap
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