Array flattening
Objective
Write a function to flatten an array of arrays
Requirements
The function should be called
flatten
It should take a single parameter,
arrays
, which is an array of arraysIt should return a new array
The function should not use the built-in array methods
flat
orflatMap
Check your solution
Tests
Function name is flatten | |||
flatten([1,2,[3,4]]) | Expected: | [1,2,3,4] | |
flatten([0,"ipsum",[1,"ipsum",[2]]]) | Expected: | [0,"ipsum",1,"ipsum",2] |
Evaluation Criteria
If I gave you this test, here's what I'd be looking for:
Understanding of recursion
The test array contains nested arrays, so you'll need to use recursion to handle them
Problem-solving skills
This would be an easy test if I allowed you to use the `flat` method, by telling you not to use it - I'm looking to see if you can think around it
Good understanding of array methods
Answering this question will require a decent level of understanding of the default array methods.
Edge cases
I'm not specifically asking for it, but bonus points if your solution can handle empty arrays