当前位置:网站首页>编写方法将一个数组扁平化并且去重和递增排序
编写方法将一个数组扁平化并且去重和递增排序
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))
边栏推荐
- Golang must know the Go Mod command
- 基于单片机GSM的防火防盗系统的设计
- 【Acwing】The 62nd Weekly Game Solution
- 二叉树非递归遍历
- Judging decimal points and rounding of decimal operations in Golang
- Dry goods | 10 tips for MySQL add, delete, change query performance optimization
- UOS统信系统 - WindTerm使用
- @JsonFormat(pattern=“yyyy-MM-dd“)时间差问题
- 一文带你了解 Grafana 最新开源项目 Mimir 的前世今生
- Unity - LineRenderer show a line
猜你喜欢
Daily practice——Randomly generate an integer between 1-100 and see how many times you can guess.Requirements: The number of guesses cannot exceed 7 times, and after each guess, it will prompt "bigger"
Judging decimal points and rounding of decimal operations in Golang
Go1.18 upgrade function - Fuzz test from scratch in Go language
程序进程和线程(线程的并发与并行)以及线程的基本创建和使用
《ArchSummit:时代的呐喊,技术人听得到》
Flink_CDC construction and simple use
[Code Hoof Set Novice Village 600 Questions] Leading to the combination of formulas and programs
基于mysql的消息队列设计
手写一个简单的web服务器(B/S架构)
(26) About menu of the top menu of Blender source code analysis
随机推荐
Weekly Summary
SQL injection Less38 (stack injection)
C程序设计-方法与实践(清华大学出版社)习题解析
一文概述:VPN的基本模型及业务类型
The article you worked so hard to write may not be your original
新产品如何进行网络推广?
Several methods for deleting specified elements in Golang slices
Audio alignment using cross-correlation
SQL注入 Less54(限制次数的SQL注入+union注入)
Qualcomm cDSP simple programming example (to query Qualcomm cDSP usage, signature), RK3588 npu usage query
Transfer Learning - Domain Adaptation
[QNX Hypervisor 2.2 User Manual]9.16 system
SQL injection Less42 (POST type stack injection)
C#中引用类型的变量做为参数在方法调用时加不加 ref 关键字的不同之处
Go1.18 upgrade function - Fuzz test from scratch in Go language
@JsonFormat(pattern=“yyyy-MM-dd“)时间差问题
Dry goods | 10 tips for MySQL add, delete, change query performance optimization
SQL27 View user details of different age groups
MySQL数据库‘反斜杠\’ ,‘单引号‘’,‘双引号“’,‘null’无法存储
Flink_CDC construction and simple use