Skip to content

Instantly share code, notes, and snippets.

@Sabineth17
Last active September 27, 2018 20:40
Show Gist options
  • Select an option

  • Save Sabineth17/c6c5e9047f0d0ed476c733aca976e7db to your computer and use it in GitHub Desktop.

Select an option

Save Sabineth17/c6c5e9047f0d0ed476c733aca976e7db to your computer and use it in GitHub Desktop.
Test_Writing_Exercise
# banana = [1,'Peter', nil,[2,3,nil,4],'Sabine',[nil],5]
# olives = [[nil, nil, nil],'Paula','Joyce',[1,2,3,4,[6,6,nil,78],nil]]
def flatten_array(array)
new_array = array.flatten.compact
end
# flatten_array(banana)
# flatten_array(olives)
##### Pseudocode exercise:
# When provided an array that is:
# - nested,
# - containing strings or integers or both,
# - AND with nil values
# --> my method flatten_array needs to clear all the nested arrays,
# maintain the values of the cleared nested arrays into one flat array.
# This method also needs to simultaneously clear/delete all the 'nil' values from the flatten array.
# The output needs to be a flatten array with the original values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment