Created
April 6, 2016 10:09
-
-
Save josephok/f8f06e1e117c5c8229ea2cd4c6ef4dfb to your computer and use it in GitHub Desktop.
scala for the impatient excercises chapter 3 excercise 2
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
def swap_array(a: Array[Int]) = { | |
for (i <- 0 until a.length) { | |
if ((i % 2 == 0) && (i+1) < a.length) { | |
val t = a(i) | |
a(i) = a(i+1) | |
a(i+1) = t | |
} | |
} | |
a | |
} | |
val a = Array(1,2,3,4,5,6) | |
println(a.toList) | |
println(swap_array(a).toList) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment