Skip to content

Instantly share code, notes, and snippets.

Avatar
🍤

Mehdi mehdi-S

🍤
  • Paris
View GitHub Profile
@mehdi-S
mehdi-S / flattenArray.swift
Last active Apr 8, 2018
Swift code that flatten nested integer array for job application at citrusByte (you can exec this code and play with value in Xcode Playground)
View flattenArray.swift
import Foundation
// nestedArrays will be a sample case to test our function
var nestedArrays = [[1,2,[3,[4,5]]],6] as [Any]
func flattenArray(nestedArrays array: [Any]) -> [Int]{
var newArray = [Int]()
array.forEach { item in
// recursively check is array item is an array, if so, pass it to flattenArray func
if let arrayItem = item as? [Any] {