Byte jitter front end face questions two

1, multi-dimensional arrays flat. Source array [[0], [2,3,4], 1, [1, [2,3]]], the output [0,2,3,4,1,1,2,3]

{// determines whether a current array subarray
         function hasChildArray (ARR) {
           return arr.some (Element => {
             IF (Array.isArray (Element)) { 
              has = to true ;
               return  to true ; 
            } 
          }); 
        } 
        the let sourceArr = [[0], [2,. 3,. 4],. 1, [. 1, [2,. 3 ]]]; 
        the let Result = []; 
     // recursive (
function doFunc (ARR) { IF (hasChildArray (ARR)) { for (the let I = 0, L = arr.length; I <L; I ++) { if (typeof arr[i] == "number") { result.push(arr[i]); } else if (Array.isArray(arr[i])) { doFunc(arr[i]); } } } else { result=result.concat(arr); } })(sourceArr); console.log(result); }

 

2, binary Tree, determines whether there is a complete path, and the value for the target, a path on which the Boolean output nodes

Guess you like

Origin www.cnblogs.com/kaima/p/11424752.html