Created
July 2, 2016 23:35
-
-
Save jose-roberto-abreu/2a92a4814391b6e18d01e0f733e3b006 to your computer and use it in GitHub Desktop.
Reverse a list of [Int] recursive
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
func reverseArr(arr:[Int])->[Int]{ | |
return arr.count <= 0 ? [] : reverseArr(Array(arr[1..<arr.count])) + [arr[0]] | |
} | |
var otherValues:[Int] = [1,2,3,4,5,6,7,8,9,10] | |
reverseArr(otherValues) // Print: 10,9,8,7,6,5,4,3,2,1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment