当前位置:网站首页>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))

边栏推荐
- Explorer TSSD 2019 software installation package download and installation tutorial
- Daily three questions 7.15
- Simulate the implementation of strstr
- Tp5.0 background admin access
- Componentization and modularization
- Three ways to solve your performance management problems
- Application method and practical case of sqlmap of penetration test SQL injection
- The latest interview questions and analysis of software testing in 2022
- HAC cluster is modified to stand-alone
- Coal industry supply chain centralized mining system: digitalization to promote the transformation and upgrading of coal industry
猜你喜欢

2022-07-19: all factors of F (I): I are added up after each factor is squared. For example, f (10) = 1 square + 2 square + 5 square + 10 square = 1 + 4 + 25 + 100 = 130.

Arduino + si5351 square wave generator

Arduino IDE for raspberry PI Pico development firmware localization installation tutorial

What are you working for? Don't give up is our only choice, come on, everyone

Consul cluster deployment

Details of C language compilation preprocessing and comparison of macros and functions

Unity refers to a variable in another class (its own instance)

Mgre.hdlc.ppp.chap.nat comprehensive experiment

Cookies and sessions

Wechat sports field reservation of applet completion works applet graduation design (8) graduation design thesis template
随机推荐
Wechat sports field reservation of the finished works of the applet graduation project (6) opening defense ppt
Strategy mode, just read one article
Mgre.hdlc.ppp.chap.nat comprehensive experiment
Routing policy interferes with routing
6. Object storage
English grammar_ Reflexive pronoun
Cloudrev deploy your own public cloud disk (pagoda installation method)
Mp4 package analysis
YouTube Download and (batch) Download
"Introduction to interface testing" punch in day06: interface testing platform: are tools and frameworks incompatible?
"No such plugin: cloudbees folder" solution appears when Jenkins selects the recommended plug-in for the first time
[C language] program compilation (preprocessing)
Introduction to web security telent testing and defense
Rotating frame target detection mmrotate v0.3.1 training hrsc2016 data set (II)
File file name change
Study notes of filebeat
Keil compile download error: no algorithm found for: 08000000h - 08001233h solution
Remote sensing image classification tool and visualization application of WebGIS
On the economic model of open source ecology
[TinyML]EfficientFormer:Vision Transformers at MobileNet Speed