Skip to content

Commit a06f834

Browse files
authored
Update js codes.docx
1 parent 81b4522 commit a06f834

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

js codes.docx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3410,7 +3410,17 @@ function sumofTwopair(arr, target){
34103410
}
34113411
console.log(sumofTwopair([0,2,3,0,50,0,3,0,8,2,0],5))
34123412
=======================================================================================================================================================================
3413-
3413+
Polyfill of Flat:
3414+
function flatArray(arr){
3415+
let result = arr.reduce((accum, item)=>{
3416+
Array.isArray(item)
3417+
? accum.push(...flatArray(item))
3418+
: accum.push(item);
3419+
return accum
3420+
},[])
3421+
return result;
3422+
}
3423+
console.log(flatArray([1,2,3,[4,[5,[6,7,[8]]]]]))
34143424
=======================================================================================================================================================================
34153425

34163426
=======================================================================================================================================================================

0 commit comments

Comments
 (0)