当前位置:网站首页>Write a method to flatten an array and deduplicate and sort it incrementally
Write a method to flatten an array and deduplicate and sort it incrementally
2022-08-01 03:40:00 【Big chicken thighs are the best】
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))
边栏推荐
- The device node structure is converted into a platform_device structure
- The IDEA can't find or unable to load The main class or Module "*" must not contain The source root "*" The root already belongs to The Module "*"
- Error using ts-node
- Which interpolation is better for opencv to zoom in and out??
- Compiled on unbutu with wiringPi library and run on Raspberry Pi
- <JDBC> 批量插入 的四种实现方式:你真的get到了吗?
- Take you to experience a type programming practice
- 使用ts-node报错
- Parse the bootargs from the device tree (dtb format data)
- JS new fun(); class and instance JS is based on object language Can only act as a class by writing constructors
猜你喜欢
随机推荐
leetcode6132. Make all elements in an array equal to zero (simple, weekly)
pdb drug comprehensive database
Software Testing Weekly (Issue 82): In fact, all those who are entangled in making choices already have the answer in their hearts, and consultation is just to get the choice that they prefer.
IDEA调试
使用ts-node报错
【消息通知】用公众号模板消息怎么样?
The fledgling Xiao Li's 112th blog project notes: Wisdom cloud intelligent flower watering device actual combat (1) - basic Demo implementation
剑指offer专项突击版第16天
Summary of mobile page optimization in seconds
Game Security 03: A Simple Explanation of Buffer Overflow Attacks
一个service层需要调用另两个service层获取数据,并组装成最后的数据,数据都是list,缓存如何设计?
这个地图绘制工具太赞了,推荐~~
IDEA 找不到或无法加载主类 或 Module “*“ must not contain source root “*“ The root already belongs to module “*“
MYSQL-Batch insert data
被 CSDN,伤透了心
Simple and easy to use task queue - beanstalkd
The IDEA can't find or unable to load The main class or Module "*" must not contain The source root "*" The root already belongs to The Module "*"
How is the tree structure of the device tree reflected?
Ordinary users cannot access HGFS directory
leetcode6132. 使数组中所有元素都等于零(简单,周赛)









