Skip to content

Instantly share code, notes, and snippets.

@worthmine
Last active August 29, 2015 14:13
Show Gist options
  • Save worthmine/934cb70e9cd1b434385a to your computer and use it in GitHub Desktop.
Save worthmine/934cb70e9cd1b434385a to your computer and use it in GitHub Desktop.
it works well!
class ArrayLikePerl {
var value: [Any] = []
init(_ array :[Any] = []){
value = array
}
func count()->Int {
return self.value.count
}
func pop() -> Any? {
if self.count() == 0 { return nil }
let removed: Any? = self.value.removeAtIndex(self.value.endIndex.predecessor())
return removed
}
func push(value: Any?...) -> Any? {
for v in value {
self.value.insert(v, atIndex: self.value.endIndex)
}
return value
}
func shift() -> Any? {
if self.count() == 0 { return nil }
let removed: Any? = self.value.removeAtIndex(self.value.startIndex)
return removed
}
func unshift(value: Any?...) -> Any? {
for v in value.reverse() {
self.value.insert(v, atIndex: self.value.startIndex)
}
return value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment