当前位置:网站首页>编写方法将一个数组扁平化并且去重和递增排序
编写方法将一个数组扁平化并且去重和递增排序
2022-07-31 22:43:00 【大鸡腿最好吃】
function solution(arr){
let res=[]
let p=(arr)=>{
for(let i of arr){
if(Array.isArray(i)){
p(i)
}else{
res.push(i)
}
}
}
p(arr)
res=[...new Set(res)]
res.sort((a,b)=>a-b)
return res
}
let a=[1,[12,2,2,2,3,5,[3,[4]]]]
console.log(solution(a))
边栏推荐
- 「SDOI2016」征途 题解
- Go1.18 upgrade function - Fuzz test from scratch in Go language
- 20. Support vector machine - knowledge of mathematical principles
- 高等代数_证明_任何矩阵都相似于一个上三角矩阵
- 10大主流3D建模技术
- Dry goods | 10 tips for MySQL add, delete, change query performance optimization
- [NLP] What is the memory of the model!
- 二叉树非递归遍历
- Pytorch lstm time series prediction problem stepping on the pit "recommended collection"
- A solution to the server encountered an internal error that prevented it from fulfilling this request [easy to understand]
猜你喜欢
[NLP] What is the memory of the model!
消息队列存储消息数据的MySQL表格
Judging decimal points and rounding of decimal operations in Golang
Audio alignment using cross-correlation
Shell常用脚本:Nexus批量上传本地仓库增强版脚本(强烈推荐)
iNeuOS industrial Internet operating system, equipment operation and maintenance business and "low-code" form development tools
【Acwing】第62场周赛 题解
A high-quality WordPress download site template theme developed abroad
ECCV 2022 Huake & ETH propose OSFormer, the first one-stage Transformer framework for camouflaging instance segmentation!The code is open source!...
Qualcomm cDSP simple programming example (to query Qualcomm cDSP usage, signature), RK3588 npu usage query
随机推荐
UVM RAL model and built-in seq
21. Support Vector Machine - Introduction to Kernel Functions
@JsonFormat(pattern=“yyyy-MM-dd“)时间差问题
了解下C# 匿名方法
Verilog implements a divide-by-9 with a duty cycle of 5/18
cas and spin locks (is lightweight locks spin locks)
Shell common scripts: Nexus batch upload local warehouse enhanced version script (strongly recommended)
Advanced Algebra _ Proof _ Any matrix is similar to an upper triangular matrix
Components of TypeScript
Golang must know the Go Mod command
The uniapp applet checks and prompts for updates
Collation of knowledge points in Ningbo University NBU IT project management final exam
IJCAI2022 | 代数和逻辑约束的混合概率推理
C程序设计-方法与实践(清华大学出版社)习题解析
Design of Fire and Anti-theft System Based on Single Chip GSM
「SDOI2016」征途 题解
Chapter Six
[QNX Hypervisor 2.2 User Manual]9.16 system
C#中引用类型的变量做为参数在方法调用时加不加 ref 关键字的不同之处
Summary of the classic drawing method of histogram