JavaScript/04-flatten.js
// returns a new array with all values flattened
returns a new array with all values flattened
returns a new array with all values flattened
function flatten(arr) {
  let newArr = [];
  function checkArr(target) {
    for (let i = 0; i < target.length; i++) {
      if (Array.isArray(target[i])) {
        newArr = newArr.concat(checkArr(target[i]));
      } else {
        newArr.push(target[i]);
      }
    }
    console.log(newArr);
  }
  checkArr(arr);
  return newArr;
}
function flatten ( arr ) { let newArr = [ ] ; function checkArr ( target ) { for ( let i = 0 ; i < target . length ; i ++ ) { if ( Array . isArray ( target [ i ] ) ) { newArr = newArr . concat ( checkArr ( target [ i ] ) ) ; } else { newArr . push ( target [ i ] ) ; } } console . log ( newArr ) ; } checkArr ( arr ) ; return newArr ; }
returns a new array with all values flattened
returns a new array with all values flattened