Last active
September 7, 2017 04:00
-
-
Save NickHung1982/b47b91d4ecf918665a0675a81cf1b963 to your computer and use it in GitHub Desktop.
flatten nested
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
var returnList = [Int]() | |
public func separateArray(_ ar:[Any]) { | |
for li in ar { | |
if li is Int { | |
returnList.append(li as! Int) | |
}else{ | |
for element in li as! Array<Any> { | |
if element is Int { | |
returnList.append(element as! Int) | |
}else{ | |
separateArray(element as! Array<Any>) | |
} | |
} | |
} | |
} | |
} | |
separateArray([[1,[1,3]],2,[1,1]]) | |
print(returnList) //"[1, 1, 3, 2, 1, 1]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment