Skip to content

Instantly share code, notes, and snippets.

@longebane
longebane / flattenarray.md
Last active March 15, 2019 22:32
Flatten Array
const arr = [[1,2,[3]],4];

let flatArr = flatten(arr);

/////////
function flatten(arr) {
  //reduce = we will iterate over the array, checking each element if it is an array, and will concat it into a final array
  return arr.reduce( (a,b) => {
 if (Array.isArray(b)) {