当前位置:网站首页>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']
边栏推荐
- Protocol buffers 的问题和滥用
- Leaderboard design in game server
- NLP field history most complete must read classic papers classification, sorting and sharing (with Chinese analysis)
- 集群聊天服务器:工程目录的创建
- 【愚公系列】2022年06月 .NET架构班 084-微服务专题 Abp vNext微服务通信
- Cmake learning
- User manual of boost filesystem
- Be a professional software craftsman
- 合宙ESP32C3硬件配置信息串口打印輸出
- LeetCode_376_摆动序列
猜你喜欢

Basic knowledge of mobile phone testing

Cmake learning

Postgraduate entrance examination | advanced mathematics Chapter4 indefinite integral

Yushu A1 robot dog gesture control

手机测试相关基础知识

One of QT desktop whiteboard tools (to solve the problem of unsmooth curve -- Bezier curve)

阿里onedate分层思想

Construction and application progress of ten billion level knowledge map of meituan brain

Serveur de chat de Cluster: conception de la table de base de données

节流和防抖的说明和实现
随机推荐
手机测试相关基础知识
Use code to set activity to transparent
[attack and defense world web] difficulty four-star 12 point advanced question: confusion1
Serveur de chat de Cluster: conception de la table de base de données
Is it safe to open a securities account online?
寻找消失的类名
Day109.尚医通:集成Nacos、医院列表、下拉列表查询、医院上线功能、医院详情查询
prime_ series_ level-1
剑指 Offer II 115. 重建序列 : 拓扑排序构造题
Chapter1 数据清洗
Protocol buffers 的问题和滥用
壹沓数字机器人入选Gartner《中国AI市场指南》
如何在 pyqt 中实现桌面歌词
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.
[create birthday card application]
-2021 sorting and sharing of the latest required papers related to comparative learning
Several methods of obtaining longitude and latitude by cesium
Proof of green Tao theorem (1): preparation, notation and Gowers norm
[Yugong series] June 2022.Net architecture class 084- micro service topic ABP vNext micro service communication
程序员成长第二十六篇:如何开好每日晨会?