Last active
August 29, 2015 14:13
-
-
Save worthmine/934cb70e9cd1b434385a to your computer and use it in GitHub Desktop.
it works well!
This file contains 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
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