当前位置:网站首页>Given an array composed of numbers, realize the name whose output ID is a number and sorted from small to large
Given an array composed of numbers, realize the name whose output ID is a number and sorted from small to large
2022-07-23 21:41:00 【Wei Xiao】
Given an array of numbers , Achieve output id Is the number , And sort from small to large name( Please use es6 grammar )
JavaScript
// Invoke the sample
const source = [
{
id: 4, name: 'test1' },
{
id: {
}, name: 'ssdf' },
"test",
{
id: () => {
}, name: 'sf' },
{
id: '6', name: 'test3' },
{
id: 6, name: 'test4' },
{
id: 7, name: 'test7' },
{
id: 2, name: 'test2' },
{
name: 'sf' },
{
},
]
// Method 1 :
function filterSort(source) {
// Write down your code
let arr = []
newValue = source.filter((v, i) => {
return typeof (v.id) == 'number'
})
newValue.sort(function (a, b) {
return a.id - b.id
})
for (v of newValue) {
arr.push(v.name)
}
return arr
}
// Method 2 :
function filterSort(arr) {
// Write down your code
return arr.filter(item => item.id === +item.id).sort((a,b)=>a.id-b.id).map(item=>item.name);
}
filterSort(source)
// The output is as follows
['test2', 'test1', 'test4', 'test7']
边栏推荐
- 集群聊天服务器:网络模块ChatServer
- 告诉我十大证券公司?请问网上开户安全么?
- Kuberntes cloud native combat VI uses rook to build CEPH cluster
- Use Gaode map JS API 2.0 to load the starting and ending path tracks
- 启牛是什么?请问一下手机开户股票开户安全吗?
- 集群聊天服务器:数据库表的设计
- Is it safe to open a securities account online?
- Flink principle and development summary (detailed)
- Jianzhi offer II 115. reconstruction sequence: topological sorting construction problem
- Scala programming (elementary)
猜你喜欢
![[attack and defense world web] difficulty four-star 12 point advanced question: confusion1](/img/ee/3ce5cc3004f9113bbf70e0c52ff4d9.png)
[attack and defense world web] difficulty four-star 12 point advanced question: confusion1

Compare kernelshap and treeshap based on speed, complexity and other factors

At 12 o'clock on July 23, 2022, the deviation from the top of the line of love life hour appeared, maintaining a downward trend and waiting for the rebound signal.

阿里onedate分层思想

High numbers | calculation of double integral 4 | high numbers | handwritten notes

壹沓数字机器人入选Gartner《中国AI市场指南》
![[complex overloaded operator]](/img/ff/aafaa9471a1bd6ef57f6a619449e80.png)
[complex overloaded operator]

Edge cloud | 1. overview

How to get the worker's hat? Where is the worker's helmet?

Cluster chat server: how to solve the problem of cross server communication | redis publish subscribe
随机推荐
Qt桌面白板工具其一(解决曲线不平滑的问题——贝塞尔曲线)
&9 nodemon自动重启工具
[complex overloaded operator]
集群聊天服务器:集群与分布式理论
Edge cloud | 1. overview
Cluster chat server: chatservice business layer
Cluster chat server: creation of project directory
BroadCast(广播)
-2021 sorting and sharing of the latest required papers related to comparative learning
Boost Filesystem使用手册
Kuberntes cloud native combat VI uses rook to build CEPH cluster
Chapter 2 回归
[arXiv] notes on uploading papers for the first time
欧氏聚类(API)及其单木分割
Openlayers instance animated GIF GIF animation
Cluster chat server: Framework Design of model data layer and encapsulation of database code
分布式能源的不确定性——风速测试(Matlab代码实现)
High numbers | calculation of double integral 4 | high numbers | handwritten notes
面试快速复习(三):概率论与数理统计
Principle and implementation of hash table, unordered set and mapping