当前位置:网站首页>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))
边栏推荐
- MySQL3
- Basic Theoretical Knowledge of Software Testing - Use Cases
- lua entry case combat 123DIY
- 787. Merge Sort
- 内核的解压缩过程详解
- 【 Make YOLO Great Again 】 YOLOv1 v7 full range with large parsing (Neck)
- JS new fun(); class and instance JS is based on object language Can only act as a class by writing constructors
- 测试
- New York University et al | TM-Vec: Template Modeling Vectors for Rapid Homology Detection and Alignment
- Handwritten binary search tree and test
猜你喜欢

Talking about hardware device computing storage and data interaction

树莓派 的 arm 版的 gcc 安装 和环境变量的配置

<JDBC> 批量插入 的四种实现方式:你真的get到了吗?

Flutter "Hello world" program code

JS new fun(); 类与实例 JS基于对象语言 只能通过书写构造函数充当类

【分层强化学习】HIRO:Data-Efficient Hierarchical Reinforcement Learning

Browser download shortcut to desktop (PWA)

解决IDEA默认情况下新建文件时,右击,new,没有XML文件的问题

leetcode6132. Make all elements in an array equal to zero (simple, weekly)

移动端页面秒开优化总结
随机推荐
Completely closed Chrome updated and in the top right corner of the tip
Replacing the Raspberry Pi Kernel
软考高级系统架构设计师系列之:信息系统基础知识
Basic use of vim - command mode
Solve the problem that when IDEA creates a new file by default, right-click, new, there is no XML file
Simple and easy to use task queue - beanstalkd
IDEA无法识别module(module右下角没有蓝色小方块)
对无限debugger的一种处理方式
787. Merge Sort
大佬们,MySQL cdc source在增量过程中回收 replication slave 和 r
剑指offer专项突击版第16天
785. Quick Sort
二舅
移动端页面秒开优化总结
Browser download shortcut to desktop (PWA)
Raspberry pie arm version of GCC installed configuration and environment variables
Nmap 操作手册 - 完整版
初出茅庐的小李第113篇博客项目笔记之机智云智能浇花器实战(2)-基础Demo实现
[SemiDrive source code analysis] series article link summary (full)
JS new fun(); class and instance JS is based on object language Can only act as a class by writing constructors