JSFiddle - React, Tailwind, and code Playground
JavaScript
// write a functin that takes an array as a parameter and returns a flattened array.
// example flatten([]) => []
// flatten([1, 2, 3]) => [1, 2, 3]
// flatten([1, 2, [3, 4]]) => [1, 2, 3, 4]
const getFlatArray = (array = []) => {
return array.map((o) => {
if(o.length) {
return getFlatArray(o);
} else {
return o;
}
})
}
const flatten = (array) => {
let results = getFlatArray(array)
console.log(results)
}
console.log('hi')