Skip to content

Commit

Permalink
Solution and Test for Issue llipio#116
Browse files Browse the repository at this point in the history
  • Loading branch information
Himanshu1495 committed Sep 19, 2017
1 parent 8009870 commit a4d21ec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions solutions/sol116.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#Himanshu Nachane (@Himanshu1495)
'''input: [1, 2, [2, [5, 3, 4]] ]
output: [1,2, 3, 5, 3, 4]
the output order does not matter, just so long as the array is flattened
'''

def flatten_array(arr):
for i in arr:
if len(str(i)) == 1:
store.append(i)
else:
flatten_array(i)
return store
store = []
10 changes: 10 additions & 0 deletions test/116.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import sys
sys.path.insert(0,'../solutions/')
from sol116 import flatten_array
import unittest

class MyTest(unittest.TestCase):
def test1(self):
self.assertEqual(flatten_array([1,2,[3,4,5],[6,[7,8]],9]),[1,2,3,4,5,6,7,8,9])

unittest.main()

0 comments on commit a4d21ec

Please sign in to comment.