Skip to content

Instantly share code, notes, and snippets.

@jose-roberto-abreu
Created July 2, 2016 23:35
Show Gist options
  • Save jose-roberto-abreu/2a92a4814391b6e18d01e0f733e3b006 to your computer and use it in GitHub Desktop.
Save jose-roberto-abreu/2a92a4814391b6e18d01e0f733e3b006 to your computer and use it in GitHub Desktop.
Reverse a list of [Int] recursive
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