当前位置:网站首页>JS written test question -- realize the flat function of array
JS written test question -- realize the flat function of array
2022-07-25 02:49:00 【H5_ ljy】
Array.prototype.myflat=function(count){
let arr=[];
// Traversing the members of an array
for(let i=0;i<this.length;i++){
// Determine whether members are arrays
if(this[i].constructor==Array&&count>0){ // When the dimension is <=0 Then stop
// If it is an array, use the idea of function self calling , Cycle again
let arr1=this[i].myflat(count-1) // here count It represents the descending dimension
// Ergodic out arr1 Members of , Put in what we return arr in Because we call the function to return an array, we have to traverse
arr.push(...arr1)
}else{arr.push(this[i])}
}
return arr;
}
var arr=[[1,2,3],8,9,[[1,2],[2,3]],[[[1,2]]]]
console.log(arr.myflat(3))

边栏推荐
- SQL Server 2022 installation
- Resolved (the latest version of selenium reported an error) attributeerror: module 'selenium webdriver‘ has no attribute ‘PhantomJS‘
- Generator set work arrangement problem code
- After six years of precipitation, new consumption has found a digital transformation paradigm
- Remote sensing image classification tool and visualization application of WebGIS
- Beginners must see the markdown User Guide
- Wechat sports field reservation of the finished works of the applet graduation project (5) assignment
- Inheritance (prototype)
- QT realizes calendar beautification
- Pagoda workman WSS reverse proxy socket legal domain name applet chat remove port
猜你喜欢

Tp5.1 paging (with parameter transfer)

C language: Structure -- a detailed explanation of memory byte alignment

Nuscenes data set summary

Project management tool Zen

ByteDance confirmation will be self-developed chip: for internal use only; Musk: I have uploaded my brain to the cloud; Go language product head leaves | geek headline

Do you know about real-time 3D rendering? Real time rendering software and application scenarios are coming

Visualization of correlation coefficient matrix

Get to know string thoroughly

【C】 Advanced knowledge of file operation

Keil compile download error: no algorithm found for: 08000000h - 08001233h solution
随机推荐
Get to know string thoroughly
YuQue - a useful tool for document writing and knowledge precipitation
BMW I3 based on clar architecture is not a simple "oil to electricity" product
Pagoda workman WSS reverse proxy socket legal domain name applet chat remove port
Redux best practices "Redux toolkit"
DLL load failed: the page file is too small to complete the operation
Can PostgreSQL CDC only connect to the main database? Connection from the library reports an error logical decoden
[jailhouse article] scheduling policies and system software architectures for mixed criticality
Summary thinking caused by the function of a SMS verification code [easy to understand]
Pycharm writes SQLite statements without code prompts
Physical experiment simulation
Tp5.1 login configuration method of whether to login public functions (complete login case)
Arduino + si5351 square wave generator
"Introduction to interface testing" punch in day08: can you save all parameters to excel for test data?
Common Oracle commands
What are you working for? Don't give up is our only choice, come on, everyone
Three ways to solve your performance management problems
Dynamic programming -- Digital DP
Project management tool Zen
JS foundation -- math